Home > Web Front-end > JS Tutorial > body text

javascript loading iframe subpage, adaptive height_javascript skills

WBOY
Release: 2016-05-16 18:55:10
Original
910 people have browsed it

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;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template