JS and jquery get the iframe of the parent window and the sub window

Source: Internet
Author: User

  This article introduces JS and jquery to obtain the parent window, the child window of the IFRAME. Need friends can come to the reference, I hope to help you.

In web development, often use IFRAME, inevitably encounter the need in the parent window to use the elements in the IFRAME, or in the IFRAME frame using the parent window elements   JS   in the parent window to get the elements in the IFRAME     1,   Format: window.frames["The name value of the IFRAME"].document.getelementbyidx_x ("ID of the control in the IFrame"). Click ();   Example: window.frames["IFM"].document.getelementbyidx_x ("Btnok"). Click ();   2,   format:   var obj=document.getelementbyidx_x ("Name of IFrame"). Contentwindow;   var ifmobj=obj.document.getelementbyidx_x ("ID of the control in the IFrame");   Ifmobj.click ();   Example:   var obj=document.getelementbyidx_x ("IFM"). Contentwindow;   var ifmobj=obj.document.getelementbyidx_x ("Btnok");   Ifmobj.click ();   Gets the element   format of the parent window in the IFRAME: window.parent.document.getElementByIdx_x (the element ID of the parent window). Click ();   Example: window.parent.document.getElementByIdx_x ("Btnok"). Click ();   jquery   Getting the elements in the IFRAME in the parent window     1,   format: $ ("#iframe的ID"). Contents (). Find ("#iframe中的控件ID"). Click ();//jquery Method 1   Example: $ ("#ifm"). Contents (). Find ("#btnOk"). Click ();//jquery Method 1   2,   Format: $ ("#iframe中的控件ID", Document.frames ("Name of Frame"). Document). Click ();//jquery Method 2   instance: $ ("#btnOk", Document.frames ("IFM"). Document). Click ();//jquery Method 2   Get the element   format of the parent window in the IFRAME: $ (' #父窗口中的元素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.