Home  >  Article  >  Web Front-end  >  Mutual access between HTML parent window and variables in IFRAME_html/css_WEB-ITnose

Mutual access between HTML parent window and variables in IFRAME_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:46:341217browse

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);

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