Home  >  Article  >  Web Front-end  >  Collection of mutual calling methods between iframe parent window and child window_javascript skills

Collection of mutual calling methods between iframe parent window and child window_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:13:45957browse
1. The parent window calls the iframe child window method
1. HTML syntax:
2. The parent window calls the child window: myFrame.window.functionName();
3. The child window calls the parent window: parent.functionName();
Simply put, it is the variable or function called in the child window Just add parent.
4. Parent window page source code:
Copy the code The code is as follows:










5. Sub-window page:
Copy code The code is as follows:










2. How to call each other between iframe parent window and child window
1. How to use in IE:
The parent window calls the child window: iframe_ID.iframe_document_object.object_attribute = attribute_value
Example: onClick="iframe_text.myH1.innerText='http://www.pint.com';"
The child window calls the parent window: parent.parent_document_object.object_attribute = attribute_value
Example: onclick="parent.myH1.innerText='http://www.pint.com';"
2. How to use it in Firefox :
The above works fine under IE, but not under Firefox. Under Firefox, the calling method should be as follows:
The parent window calls the child window: window.frames["iframe_ID"].document.getElementById("iframe_document_object").object_attribute = attribute_value
Example: window.frames[" iframe_text"].document.getElementById("myH1").innerHTML= "http://hi.jb51.net";
The child window calls the parent window: parent.document.getElementById("parent_document_object").object_attribute = attribute_value
Example: parent.document.getElementById("myH1").innerHTML = "http://jb51.net";
3. Complete example
test.htm
Copy code The code is as follows:



Test Page











d





frame_test.htm
Copy code The code is as follows:





无标题文档



ha














test.htm里面firefox下访问iframe 必须用name,不能用id,所以要改为name="iframe_test" 。(http://chenling1018.blog.163.com/blog/static/1480254200811891041694/)
三、在c#中如何动态改变iframe的src值,动态指向一个网页
1)如果是javascript脚本
给iframe加一个ID如