javascript - iFrame expands with content but does not shrink -
I have a cross domain iframe. The actual iframe works fine and displays the page at 100% height.
My problem is the first page is 1200px, if you click on a link within the iframe and the next page is 800px, then you get 400px free space below.
Therefore the IFrame grows up to fit the content, but will not shrink. Below is my code:
The code that goes to the page for iframe:
The code that goes to the page receiving iFrame:
& lt; Script type = "text / javascript" & gt; Function resized CrossDomainIframe (id, other_domain) {var iframe = document.getElementById (id); Window.addEventListener ('message', function (event) {if (event.origin! == other_domain) Returns; // Only accept messages from specified domains if returns (isNaN (event.data)); // only a few Accepts which can be parsed as a number var altitude = persian (event.data) + 32; // scrollbar iframe.height = height + "px";}, false) to avoid some extra height Add } & Lt; / Script & gt; & Lt; Iframe src = 'http: //example.com/page_containing_iframe.html' id = "my_iframe" onload = "resize crossderman iframe ('my_iframe', 'http://example.com');" & Gt; & Lt; / Iframe & gt; Does anyone know how to modify javascript, which is also small?
Thanks
Other_domain equivalent in your script 'http://example.com ' - always. So if you click on 'http://example.com/somepage.html', then your function will always return before the resizing of the iframe. Instead of equal, you should use
(event.origin.lastIndexOf (other_domain, 0)! == 0) Return;
Comments
Post a Comment