Obtain iframe from the parent form
Window. iframeId
Iframe get parent window
Window. parent
Parent.html
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Insert title here </title>
<Script type = "text/javascript">
Function btnFn (){
Window. subWin. test ();
}
Function get (name ){
Return document. getElementById (name );
}
</Script>
</Head>
<Body>
<Input id = "name" type = "text" value = "222">
<Input type = "button" id = "btn" value = "click" onclick = "btnFn ();"> <br/>
<Br/>
<Iframe src = "sub.html" id = "subWin"
Name = "subWin" width = "100%" marginwidth = "0" height = "100%"
Marginheight = "0" scrolling = "Yes" frameborder = "0" valign = "middle"
Resize = "no" style = "display: block; border: 3px solid red;"> </iframe>
</Body>
</Html>
Sub.html
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Insert title here </title>
<Script type = "text/javascript">
Function test (){
Alert (window. parent. get ("name"). value); // result: 222
}
</Script>
</Head>
<Body>
I am the content of the form
</Body>
</Html>