JavaScript gets the method of the element value in the IFRAME page

Source: Internet
Author: User

  This article is mainly on the JavaScript to obtain an IFRAME in the page elements of the value of the method is introduced, need friends can come to the reference, I hope to help you.

ie method: document.frames[' MyFrame '].document.getelementbyid (' test '). Value;   Firefox method: document.getElementById (' MyFrame '). ContentWindow.document.getElementById (' Test '). Value;   IE, Firefox method:   Code as follows:     function GetValue () {             var tmp = '';              if (document.frames) {              &NBS P     TMP + = "Brother IE said: ';                     tmp + document.frames[' myframe '].document.getelemen Tbyid (' Test '). Value;              }else{                  &NBS P TMP = document.getElementById (' MyFrame '). ContentWindow.document.getElementById (' test ') .value;               }              alert (TMP);        }     Sample code: Code in a.html page   code as follows: <html>             <head>             &NBS P   <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">                 <title>         &NBSP ;           JavaScript get the value of the elements in the IFRAME page test                 </title>            </head>            <BODY&GT ;                 <iframe id= "MyFrame" src= ' b.html ' style= "width:300px;height:50" px; " ></iframe>                 <input type= "button" id= "btn" onclick= "Getv Alue () "value=" Test ">                 <script type=" Text/javascript "> &N Bsp                       function GetValue () {                          &NB Sp var tmp = ';                             if (document.frames) {&NB Sp                                   TMP + + brother said: ';                                   &NB Sp TMP = = document.frames[' myframe '].document.getelementbyid (' test '). Value;                            }else{    &NB Sp                               TMP = document.ge Telementbyid (' MyFrame '). ContentWindow.document.getElementById (' test ') .value;                    &NBSP        }                           & nbsp Alert (TMP);                                   & nbsp     </script>             </body>         </htm The code code for the l>   b.html page is as follows:        <html>             <head >                 <meta http-equiv= "Content-type content=" text/html; Charset=utf-8 ">                 <title>         &NBSP ;           I am an iframe page                 </title> &N Bsp           </head>             <body>                <input type= ' text ' id= ' test ' value= ' welcome: justflyhigh.com ' >     & nbsp       </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.