Skip to content
Advertisement

Resizing ‘iframe’ after inside content is loaded

I have an iFrame in which I am loading a page which uses ajax to load data after various page labels are clicked. Now I am using Javascript function to calculate loaded-data height for replacing iframe’s height which results into resizing iframe and thus avoids scrollbars. Now my problem is script gets called as soon as labels are clicked, but data is still loading. Kindly tell me something I can use to wait till ajax is finished loading data and then calling my function.

I am using the following script:

JavaScript

and my html is as following:

JavaScript

The above code works fine for me (iframe/src url both are in same domain.) I also want to get the height of a div element which is in iframe content window page. How do I grab that?

Advertisement

Answer

html

JavaScript

javascript/jquery:

JavaScript

The trick here is frame.load method waits for the frame to load. After that the height and width is manipulated as required. Here i am setting is to cover whole of the screen. And the page contains only a iframe and nothing else.

Kind Regards.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement