Method of element access in the jquery IFRAME parent-child framework

Source: Internet
Author: User

jquery Tutorials

In web development, an IFRAME is often used, and it is unavoidable to encounter elements in the IFRAME that need to be used in the parent window, or to use the parent window in the IFRAME framework
Js
Gets the elements in the IFRAME in the parent window
1.
Format: window.frames["The name value of the IFRAME"].document.getelementbyid ("ID of the control in the IFrame"). Click ();
Example: window.frames["IFM"].document.getelementbyid ("Btnok"). Click ();
2.
Format:
var Obj=document.getelementbyid ("Name of IFrame"). Contentwindow;
var Ifmobj=obj.document.getelementbyid ("ID of the control in the IFrame");
Ifmobj.click ();
Instance:
var Obj=document.getelementbyid ("IFM"). Contentwindow;
var Ifmobj=obj.document.getelementbyid ("Btnok");
Ifmobj.click ();
Gets the element of the parent window in the IFRAME
Format: Window.parent.document.getElementById (the element ID of the parent window). Click ();
Example: Window.parent.document.getElementById ("Btnok"). Click ();
Jquery
Gets the elements in the IFRAME in the parent window
1.
Format: $ ("#iframe的ID"). Contents (). Find ("#iframe中的控件ID"). Click ();//jquery Method 1
Instance: $ ("#ifm"). Contents (). Find ("#btnOk"). Click ();//jquery Method 1
2.
Format: $ ("#iframe中的控件ID", Document.frames ("frame name"). Document). Click ();//jquery Method 2
Instance: $ ("#btnOk", Document.frames ("IFM"). Document). Click ();//jquery Method 2
Gets the element of the parent window in the IFRAME
Format: $ (' #父窗口中的元素ID ', parent.document). Click ();
Example: $ (' #btnOk ', parent.document). Click ();


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.