1. The parent window calls the iframe subwindow method.
1. HTML Syntax: <iframe name = "myFrame" src = "child.html"> </iframe>
2. Parent window: myFrame. window. functionName ();
3. subwindow: parent. functionName ();
Simply put, add a parent before the variable or function called in the subwindow.
4. source code of the parent window page:
Copy codeThe Code is as follows:
<Head>
<Script type = "text/javascript">
Function say (){
Alert ("parent.html ------> I'm at parent.html ");
}
Function callChild ()
{
// Document. frames ("myFrame"). f1 ();
MyFrame. window. say ();
}
</Script>
</Head>
<Body>
<Input type = button value = "Call the function say () in child.html" onclick = "callChild ()">
<Iframe name = "myFrame" src = "child.html"> </iframe>
</Body>
</Html>
5. subwindow page:Copy codeThe Code is as follows:
<Head>
<Script type = "text/javascript">
Function say ()
{
Alert ("child.html ---> I'm at child.html ");
}
Function callParent (){
Parent. say ();
}
</Script>
</Head>
<Body>
<Input type = button value = "Call the say () function in parent.html" onclick = "callParent ()">
</Body>
</Html>
Ii. Mutual call between the iframe parent window and Child Window
1. How to Use IE:
Parent window: iframe_ID.iframe_document_object.object_attribute = attribute_value
Example: onClick = "iframe_text.myH1.innerText = 'HTTP: // www.pint.com ';"
Child Window call parent window: parent. parent_document_object.object_attribute = attribute_value
Example: onclick = "parent. myH1.innerText = 'HTTP: // www.pint.com ';"
2. Usage in Firefox:
There is no problem in IE, but it is not normal in firefox. In firefox, the following call method should be used:
Parent window: window. frames ["iframe_ID" ..doc ument. getElementById ("iframe_document_object"). object_attribute = attribute_value
Example: window. frames ["iframe_text" ].doc ument. getElementById ("myH1"). innerHTML = "http://hi.jb51.net ";
Child Window call parent window: parent.doc ument. getElementById ("parent_document_object"). object_attribute = attribute_value
Example: parent.doc ument. getElementById ("myH1"). innerHTML = "http://jb51.net ";
3. Complete example
Test.htmCopy codeThe Code is as follows: <HTML>
<HEAD>
<TITLE> Test Page </TITLE>
<Script src = "prototype-1.4.0.js"> </script>
<Script language = "javascript">
Function show ()
{
Window. frames ["iframe_text" 2.16.doc ument. getElementById ("myH1"). innerHTML = "http://hi.jb51.net ";
}
</Script>
</HEAD>
<BODY>
<Iframe height = "350" width = "600" src = "iframe_test.htm" name = "iframe_text"> </iframe>
<Form action = "" method = "post">
<Input name = "haha" id = "haha" type = "text" maxlength = "30" value = "haha"/>
<Br/>
<Textarea cols = "50" rows = "5" id = "getAttributeMethod"> </textarea>
<Input type = "button" onClick = "show ();" value = "Submit"/>
</Form>
<H1 id = "myH1"> d
</BODY>
</HTML>
Frame_test.htmCopy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<Script language = "javascript">
Function show ()
{
Parent.doc ument. getElementById ("myH1"). innerHTML = http://jb51.net;
}
</Script>
<Body>
<H1 id = "myH1"> ha
<Form action = "" method = "post">
<Input name = "abc" id = "abc" type = "text" maxlength = "30" value = "abc"/>
<Br/>
<Textarea cols = "50" rows = "10" id = "text"> </textarea>
<Br/>
<Input type = "button" value = "Submit" onclick = "show ();"/>
</Form>
</Body>
</Html>
In test.htm, the access to iframe in firefox must use name and cannot use id. Therefore, change to name = "iframe_test ". Http://chenling1018.blog.163.com/blog/static/1480254200811891041694)
3. How to dynamically change the src value of iframe in c # and dynamically point to a webpage
1) javascript scripts
Add an ID to iframe, for example, <iframe id = frmList ......
Write in script
FrmList.doc ument. location = strNewUrl
2) if it is a background program
Add an ID to iframe and runat = server, for example, <iframe id = frmList runat = server ......
Write in the program
FrmList. Attributes. Add ("src", strNewUrl );