Get the elements of an iframe and manipulate them

Source: Internet
Author: User

Get the document element in the IFRAME with a centralized approach:

1. getElementById () method and Contentwindow property:

window.onload=function/* must wait for page load to finish * /
document.getElementById ("ID of iframe"). ContentWindow.document.getElementById ("ID of element")
document.getElementById ("ID of iframe"). Contentdocument.getelementbyid ("ID of Element") }

Note: the above. Contentdocument ( cannot be used in IE, because IE does not exist in this property) is equivalent to. contentwindow.document!

2. Window. Frames property of the object

window.onload=function/* must wait for page load to finish */     window.frames[" Index or IFRAME Name property value "].document.getelementbyid (ID of element")}

The Window.frames property refers to a class array object and can be indexed by a number or form name.

WINDOW.FRAMES[0]//The first subform of a window

window.frames["The name attribute value of the iframe"]//window.frames["F1"] or WINDOW.FRAMES.F1

Note: The element in the frames[] array is the Window object, not the <iframe> element

3. The Name property value of the IFRAME

window.onload=function/* must wait for the page to load after the end of the */     iframe's Name property value. document.getElementById ("Element ID")   /* The name of the form refers to the Window object in the form * /
}

Note: You can replace FRAMES.F1 with the name "F1" of the form.

Add:

Gets the form of the IFRAME: document.getElementById ("ID of the IFRAME"). Contentwindow = window.frames["index or the Name property value of the iframe"] = The property value of the name of the IFRAME

Get the elements of an iframe and manipulate them

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.