Home > Article > Web Front-end > Mutual access between HTML parent window and variables in IFRAME_html/css_WEB-ITnose
1. HTML parent window accesses variables or functions in IFRAME
Write in the parent window script:
//Call variable assignment
IframeObj.contentWindow.someVar = "test is ok";
//Call function
IframeObj.contentWindow.someFunction();
2. IFRAME in HTML accesses variables or functions in the parent window
Assume that there is a method in the parent window script:
function showMsg(str){
alert ('Read from iframe:' str);
}
Then in IFRAME you can call the showMsg() function of the parent window like this:
var str = 'Wahaha!';
window.parent.showMsg(str);