Dynamically change the height of the IFrame to realize the automatic expansion of the IFrame and the automatic shrinking of the parent page
Principle: When the IFrame sub-page is loaded, call the parent IFrame object to change its height
Specific implementation one:
1. In the specific page of the IFrame (that is, the sub-page), add JavaScript
<script> <br>function IFrameResize(){ <br>//alert(this.document.body.scrollHeight); //Pop up the height of the current page<br>var obj = parent.document.getElementById("childFrame"); //Get the IFrame object of the parent page<br>//alert(obj.height); //Pop up the height set in the IFrame in the parent page<br>obj.height = this. document.body.scrollHeight; //Adjust the height of the IFrame in the parent page to the height of the page <br>} <br></script>
2. On the specific page of the IFrame (that is subpage), add the onload event
< body onload="IFrameResize()">
3. Add an ID to the IFrame tag of the parent page, which is the childFrame
Specific implementation two:
//Dynamicly change the height of the parent iframe
//JS called by the iframe page
$(function(){
//Get the height of the window
var winH = $(window).height();
//Get the height of the page
var bodyH = $(document).height();
if(bodyH > winH){
window.parent.document.getElementById("mainFrame").height=bodyH;
}else{
window.parent.document.getElementById("mainFrame").height=winH;
}
});
The iframe of the parent page is
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