There are roughly two traditional approaches:
Method one, after each contained page in its own content loaded, execute JS to get the height of this page, and then to sync the parent page of the iframe height.
Method Two, in the main page iframe in the OnLoad event to execute JS, to get the content of the page contains the height, and then go to sync height.
In terms of code maintenance, method Two is better than method one, because method one, each included page is to introduce a piece of the same code to do this thing, create a lot of copies.
Two methods are only to deal with static things, that is, only when the content loading, if JS to operate the DOM caused by the height of changes, are not very convenient
<!doctype HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ""
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>iframe Adaptive height </title>
<script type=" text/web Effects ">
function Reinitiframe () {
var iframe = document.getElementById ("frame_content");
try{
var bheight = iframe.contentwindow.document.body.scrollheight;
var dheight = iframe.contentwindow.document.documentelement.scrollheight;
var height = Math.max (bheight, dheight);
Iframe.height = height;
}catch (ex) {}
}
Window.setinterval ("Reinitiframe ()");
function Checkheight () {
var iframe = document.getElementById ("frame_content");
var bheight = iframe.contentwindow.document.body.scrollheight;
var dheight = iframe.contentwindow.document.documentelement.scrollheight;
Alert ("Bheight:" + bheight + ", Dheight:" + dheight);
}
</script>
<body>
<iframe src= "http://www.111cn.net" frameborder= "0" width= "100%" "scrolling=" No "id=" Frame_content "onload=" This.height=20 "allowtransparency=" true ></iframe>
Note ID and onload
Then add a JS
</body>
Tell me more about
iframe, especially without the border of the IFRAME because it can and the seamless combination of Web pages so as not to refresh the page in the case of some of the data to update the page is possible, but the size of the IFRAME is not like the layer can be "scalable", so that the use of trouble, to the IFRAME set Degree of time is not good, less is not, now, let me tell you an iframe dynamic adjustment of the height of the method, mainly the following JS function:
Program code
Function setwinheight (obj)
{
var win=obj
if documen T.getelementbyid)
{
if (Win &&! Window.opera)
{
if (win.contentdocument && win.contentdocument.body.offsetheight)
win.height = Win.contentdocument.body.offsetheight;
Else if (win.document && Win.document.body.scrollheight)
win.height = win.document.body.scrollheight;
}
}
}
Finally, join the IFRAME, can not lose the onload attribute, of course, ID must also be in the function of the win match