Home >Web Front-end >JS Tutorial >Collection of practical iframe operations_javascript skills

Collection of practical iframe operations_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:51:291188browse

The iframe height is set to the height of the subpage

Copy code The code is as follows:

//You need to use Jquery
$(document).ready(function () {
parent.document.getElementById("ifPage").style.height = document.body.scrollHeight "px";
});

iframe is highly adaptive to the parent page
Copy code The code is as follows:

//You need to use Jquery
$(window).resize(function () {
var webheight = document.body.clientHeight - X; //X is the height that needs to be subtracted, such as the height of the top navigation
$("#ifPage").attr("style", "height:" webheight "px;");
});
$(window).load(function () {
var webheight = document.body.clientHeight - 105;
$("#ifPage").attr("style", "height:" webheight "px;");
});

Transfer elements between parent and child pages
The parent page gets the data in the child page, JS code:
Copy code The code is as follows:

//Get the object according to the id of the iframe
var i1 = window.frames['iframeId'];
//var iframe =window.frames[0] ;You can also
//Get the element value in the iframe
var val=i1.document.getElementById("t1").value

The child page gets the data in the parent page, JS code:
Copy code The code is as follows:

var val = parent.document.getElementById( "txt1");

Transfer between subpages, JS code:
Copy code The code is as follows:

var i1 = parent.window.frames['iframeId'];
var val = i1.document.getElementById("text1").value;

Refresh the parent page
Copy code The code is as follows:

function parentReload( ) { window.parent.location.reload();}

Reload subpage
Copy code The code is as follows:

iframe.Attributes[ "Src"] = "ItemTQEditorPage.aspx";
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