JavaScript application: IFRAME Adaptive to its loaded content height

Source: Internet
Author: User
Tags window
Javascript| Loading | adaptive

JavaScript application: IFRAME Adaptive to its loaded content height
Main.htm:

<meta http-equiv= ' content-type ' content= ' text/html; charset=gb2312 ' >
<meta name= ' author ' content= ' F.r.huang (meizz plum blossom Snow)//www.meizz.com ' >
<title>iframe Adaptive Load Page height </title>

<body>
<iframe src= "child.htm" ></iframe>
</body>

Child.htm:

<meta http-equiv= ' content-type ' content= ' text/html; charset=gb2312 ' >
<meta name= ' author ' content= ' F.r.huang (meizz plum blossom Snow)//www.meizz.com ' >
<title>iframe Adaptive to its loaded Web page (multi-browser compatible) </title>
<script language=javascript>
function Iframeautofit ()
{
Try
{
if (window!=parent)
{
var a = Parent.document.getElementsByTagName ("IFRAME");
for (var i=0; i<a.length; i++)//author:meizz
{
if (A[i].contentwindow==window)
{
var h = document.body.scrollHeight;
if (document.all) {h = 4;}
if (window.opera) {h = 1;}
A[i].style.height = h;
}
}
}
}
catch (ex)
{
Alert (script cannot operate across domains!) ");
}
}
if (document.attachevent) window.attachevent ("onload", Iframeautofit);
else Window.addeventlistener (' Load ', Iframeautofit, false);
</script>
<body>
<div style= "WIDTH:200;  height:400; Background-color:yellow ">
IFRAME Adaptive to its loaded Web page (multi-browser compatible)
</div>
</body>




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.