The iframe does not scale to fit the content when the Anvil app changes, but displays a scroll bar. Tested on Crome. The website and the Anvil app are under the same domain.
I tried to clone your apps and apply this, the events fire and try to access parent’s function but I hit the “cross origin” block.
If - like in your case - parent and child app share same domain then that should work for you.
The solution in case of cross-domain is called Post-message.
Here’s a link, it requires a little effort to study and understand though.
With this you can safely send a message from the child iframe to the parent page and there act consequently.
The same concept, a slightly more complex implementation I guess.
What you need to do: In the child app:
def check_box_2_change(self, **event_args):
self.column_panel.visible = self.check_box_2.checked
self.call_js('notify_parent') // add this to all events that need resizing
Then in the child app’s Native Libraries:
<script>
function notify_parent() {
window.parent.postMessage({
"action":"resize_iframe"
// add other params you need to transfer from child to parent
},"https://ygwmwb7ehysqe2jo.anvil.app"); // Set the origin: this is to avoid cross-domain abuse. Set it to the PARENT app url
}
</script>
This will trigger the message.
Then in the parent app’s Native Libraries:
<script type="text/javascript">
window.addEventListener("message", (event) => {
// Check the origin against the CHILD app url
if (event.origin !== "https://c44iw5vxkvskiivi.anvil.app")
return;
if (event.data['action'] == 'resize_iframe') {
resizeIframe();
}
}, false);
function resizeIframe() {
const frame = document.getElementById('my_iframe');
if(frame) {
try {
// Set both since style could prevail.
frame.height = "100%";
frame.style = "width:100%; height:100%;"
} catch (exception) {
return false;
}
}
}
</script>
Pay attention to set the id="my_frame" or the resizeIframe function won’t hook it.
Another thing: I preferred to simply set each time the iFrame to 100% without calculating the exact height. However, if you prefer another approach, you can calculate whatever you want on the child app, add the parameter to the dictionary and use it on the parent app at your convenience.
If you use the clone links, remeber to change appropriately the urls of parent / child used in the code.