JS get/Set Several methods of object elements and documents in IFRAME

Source: Internet
Author: User

1, ie dedicated (through frames index image positioning):

Document.frames[i].document.getelementbyid (' element id ');

2, IE dedicated (through the IFRAME name image positioning):

document.frames[' iframe name '].document.getelementbyid (' element id ');

The above method applies not only to the IFRAME, but also to the frame in the frameset. ie, although good at self-defined standards, but have to say that many of its design is more humane. For example, it provides a concise and figurative way of writing in addition to the standard paths below.

3. General Method:

document.getElementById (' ID of iframe '). Contentwindow. document. getElementById (' element ID ')

Note To add Contentwindow, the problem often arises because it is easy to ignore, it represents the window object inside the frame and the iframe .

JS Get IFRAME Document content

<script type= "Text/javascript" > Function getiframecontent () {  //Get iframe file contents var doc;if (document.all) {// IE doc = document.frames["Myiframe"].document; }else{//Standard doc = document.getElementById ("Myiframe"). Contentdocument;} return Doc.body.innerHTML;} </script>

Note: The above. Contentdocument equals. contentwindow.document!

Extended reading:

Practical Framework (IFRAME) code

JS get/Set Several methods of object elements and documents in IFRAME

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.