How to realize the adaptive height of iframe (embedded frame)

Source: Internet
Author: User
Tags copy window
Adaptive several times to see someone ask questions about how to achieve the adaptive height of the IFRAME, able to automatically adapt to the length of the page to avoid the page and IFRAME at the same time the phenomenon of the scroll bar, just I encountered similar problems in the work, so the Internet search, East copy copy West Look, out of such a function, Posted to the page can be used. Do not dare to enjoy, if you feel useful, welcome to use

The source code is as follows

<script type= "Text/javascript" >
* * IFRAME automatically adapt to the page **//

Enter a list of the names of the IFRAME that you want to automatically adjust height based on the height of the page
Separate the IDs of each iframe with commas. For example: ["myframe1", "myframe2"], you can have only one form, no commas.

Define the ID of the IFRAME
var iframeids=["Test"]

If the user's browser does not support IFrame to hide the iframe and yes to hide, no means no hidden
var iframehide= "Yes"

function Dyniframesize ()
{
var dyniframe=new Array ()
for (i=0; i<iframeids.length; i++)
{
if (document.getElementById)
{
Automatically adjust the iframe height
Dyniframe[dyniframe.length] = document.getElementById (Iframeids[i]);
if (Dyniframe[i] &&!window.opera)
{
dyniframe[i].style.display= "Block"
if (dyniframe[i].contentdocument && dyniframe[i].contentdocument.body.offsetheight)//If the user's browser is Netscape
Dyniframe[i].height = Dyniframe[i].contentdocument.body.offsetheight;
else if (dyniframe[i). Document && Dyniframe[i]. Document.body.scrollHeight)//If the user's browser is IE
Dyniframe[i].height = Dyniframe[i]. Document.body.scrollHeight;
}
}
To handle the display of browsers that do not support IFRAME based on the parameters set
if ((document.all | | document.getelementbyid) && iframehide== "No")
{
var tempobj=document.all? Document.all[iframeids[i]]: document.getElementById (Iframeids[i])
tempobj.style.display= "Block"
}
}
}

if (Window.addeventlistener)
Window.addeventlistener ("Load", Dyniframesize, False)
else if (window.attachevent)
Window.attachevent ("onload", dyniframesize)
Else
Window.onload=dyniframesize
</script>


When you use it, just stick it in the



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.