Differences between contentWindow and contentdocument and IFRAME access

Source: Internet
Author: User
A> contentWindow is compatible with various browsers and the window objects of subwindows can be obtained. B> contentdocument Firefox support,> ie support for IE8. Obtain the Document Object of the subwindow. Compatible with document objects: var getiframedoc = function () {var iobj = document. createelement ("iframe"); document. getelementsbytagname ("body") [0]. appendchild (iobj); Return iobj. contentdocument | iobj.contentw.doc ument;} basic usage: 1) document. getelementbyid ("myiframe "). after obtaining the IFRAME object from contentWindow, you can use contentWindow to obtain the window object containing the page, and then you can access the page elements normally; 2) $ ("# myiframe") [0]. contentWindow jquery selector gets IFRAME. First, convert the jquery object to a DOM object, or use the get () method to convert it. 3) $ ("# myiframe") [0]. contentWindow. $ ("# dd "). val () can be used to perform page operations after obtaining the IFRAME window object; 4) $ ("# myiframe") [0]. contentWindow. username = "zhangsan"; you can pass parameters to the IFRAME page in this way, in the IFRAME page window. username can be used to obtain the value. username is a custom global variable. 5) on the IFRAME page, you can use parent to obtain the window on the home page. Then, you can access the elements on the parent page; 7) parent. $ ("# frame_a" {0}.content}{doc ument. getelmentbyid ("# frame_ B"); For calls between IFRAME pages of the same level, you must first obtain the parent window, and then call the IFRAME of the same level to obtain the window for operation;

 

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.