Home  >  Article  >  Web Front-end  >  JavaScript application: Iframe adapts to the height of its loaded content_javascript skills

JavaScript application: Iframe adapts to the height of its loaded content_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:15:11980browse
main.htm:
Copy code The code is as follows:

< html>  
                                                     'F.R.Huang(meizz梅花雪)//www.meizz.com'>                                                                                       >                                                                      

child.htm:



(Multi-browser compatible)
{
var a = parent.document.getElementsByTagName("IFRAME");
for(var i=0; i {
if(a[i].contentWindow==window)
{
var h = document.body.scrollHeight; if(document .all) {h = 4;}
                                                                      .opera) {h = 1;}
a[i].style.height = h;
}
}
}
catch (ex)
{
alert("Script cannot be operated across domains! ");
}
}
if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
else window.addEventListener('load', iframeAutoFit, false);




iframe Adapt to the web page it loads (compatible with multiple browsers)



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Send two small things, ASP/PHP learning tools. Written in JavaScript_javascript skillsNext article:Send two small things, ASP/PHP learning tools. Written in JavaScript_javascript skills

Related articles

See more