How to use javascript to obtain the element values in the iframe page

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.