The Cubbles IFrame Resizer API
Purpose
Cubbles supports the integration of any component into a webpage using the html iframe element (See The Cubbles IFrame API). However, the iframe will not bet automatically resized to adjust its content, and you may not always be sure of the final size of the iframe.
In that case, you can use the iframe-resizer
utility to enable the Cubbles iframe
to resize according to its content. The following sections show how to use the iframe-resizer
utility to automatically resize a Cubbles iframe.
Use
If you want the Cubbles iframe
to be resized automatically according to its content size; you can use the iframe-resizer
utility. Let's suppose you want to use a Cubbles iframe
to display the cubx-maps-demo from the cubx-maps@1.0.0-SNAPSHOT, you should include an iframe html element as follows (See The Cubbles IFrame API):
Including the iframe-resizer utility
Now you need to include the utility as a script within the head of your html page. By the moment it is available at https://cubbles.world/core/cubx.core.rte@3.0.0-SNAPSHOT/iframe-resizer/resize.js. Your code should now look as follows:
Setting the iframe id
Finally you should:
make sure the id attribute of your iframe is set and
pass it to the Cubbles iframe using
iframe-id
parameter in the src url:
Remember that the id of the iframe should be the same as the iframe-id value passed as a parameter, otherwise the resizing wouldn't work.
Result
The width of the iframe will be set to 100%. The height will be set according to the body content of the iframe whenever it changes as shown below.
Check this demo to see the result running online.
Last updated