Sizing of an iFrame.

Vaibhav Paliwa2
Tera Contributor

I am trying to load contents in an iFrame, from a third-party source. The iFrame component I am using is in UI Builder. I want the size of the iFrame to be based on the contents it loaded and should be adjusted to the size of screen as well. The current sizing allows the size to be altered statically. How can I achieve this in UI builder?Screenshot 2024-09-26 173145.png

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

The iframe component won't support resizing based on the contents.

Hi Brad,
Thanks for your response!

Is there any way I could change the height of the iFrame using a script, rather than giving the height statically. Even if it is not resized based on contents, I still want it to be resized based on the screen.

I wonder do you simply want to set the height of it to 100%? So here I am setting the height of the "body" to 100%

Screenshot 2024-10-10 at 10.47.21 PM.png


and then I am doing the same in the iframe:

Screenshot 2024-10-10 at 10.47.33 PM.png

You could set the Height param to a state variable too, something like @STate.iframeHeight, but I am not sure what value you could dynamically assign to it, so perhaps just setting 100% is enough? 

Hi Kevin,

Thank you for your response!

 

I tried binding it with a state parameter but could not achieve that dynamically. I see there is an option to set the height using script. For other applications I have used method window.innerHeight to set the height of iFrame. But, I am not sure how to configure that in UI builder as I am very new to it. Any suggestions for that would be really helpful.