Home >Web Front-end >JS Tutorial >javascript loading iframe subpage, adaptive height_javascript skills

javascript loading iframe subpage, adaptive height_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 18:55:10956browse

Assume that the main page has a div with an iframe placed inside

Copy code The code is as follows:

< ;div id="frameBox">



3 menu links, loading 1.html, 2.html, 3.html respectively in the iframe pages.

The three sub-pages are executed after window.onload is loaded on their own pages respectively
Copy the code The code is as follows:

function aa(){
var newHeight = document.body.scrollHeight 20 "px";
window.parent.document.getElementById("frameBox").style.height = newHeight;
//The above firefox passes, but the following sentence must be added to ie6, otherwise the iframe height will be changed, but the visible area will not change
window.parent.document.getElementById("frameWin").style.height = newHeight;
}

The following method only needs to put the code on the main page:
Page code:
Copy code The code is as follows:





js script (added to the main page):
Copy code The code is as follows:

function test2(){
var frameWin = document.getElementById("frameWin");
var frameBox = document.getElementById("frameBox");
var newHeight;
if (frameWin.Document){
newHeight = frameWin.Document.body.scrollHeight 20 "px";
}else{
newHeight = frameWin.contentDocument.body.scrollHeight 20 "px";
}
frameWin.style.height = newHeight;
frameBox.style.height = newHeight;
}
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:JavaScript calculates the day of the month in this year_time and dateNext article:JavaScript calculates the day of the month in this year_time and date

Related articles

See more