How to use javascript to obtain the element values in the iframe page
This article mainly introduces how to use javascript to obtain the element values on the page of iframe. If you need it, you can refer to it for help.
IE Method:
Document.frames['myframe'mirror.doc ument. getElementById ('test'). value;
Firefox method:
Document.getelementbyid('myframe'{.content}doc ument. getElementById ('test'). value;
IE and Firefox methods:
The Code is as follows:
Function getValue (){
Var tmp = '';
If (document. frames ){
Tmp + = 'ie :';
Tmp + = document.frames{'myframe'}.doc ument. getElementById ('test'). value;
} Else {
Tmp = document.getelementbyid('myframe'{.content}doc ument. getElementById ('test'). value;
}
Alert (tmp );
}
Sample Code:
A.html Page code
The Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title>
Javascript to obtain the value of elements in the iframe page
</Title>
</Head>
<Body>
<Iframe id = "myFrame" srcw.' B .html 'style = "width: 300px; height: 50px;"> </iframe>
<Input type = "button" id = "btn" onclick = "getValue ()" value = "test">
<Script type = "text/javascript">
Function getValue (){
Var tmp = '';
If (document. frames ){
Tmp + = 'ie :';
Tmp + = document.frames{'myframe'}.doc ument. getElementById ('test'). value;
} Else {
Tmp = document.getelementbyid('myframe'{.content}doc ument. getElementById ('test'). value;
}
Alert (tmp );
}
</Script>
</Body>
</Html>
B .html Page code
The Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title>
I am a page in iframe
</Title>
</Head>
<Body>
<Input type = 'text' id = "test" value = 'Welcome to: justflyhigh.com '>
</Body>
</Html>