Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use contentwindow

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use contentwindow, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The contentDocument property can return documents in iframe as HTML objects, and the returned objects can be processed through all the standard DOM methods.

Definition and usage of contentwindow

Syntax: frameObject.contentWindow, or iframeObject.contentWindow (not a jquery object)

When nesting pages with iframe, if the parent page wants to get the content in the child page, you can use contentWindow or contentDocument, the difference is as follows:

1. ContentWindow this is a read-only property that returns the window object of the specified iframe. Although it is not part of the standard, all major browsers support it.

2. ContentDocumentFirefox supports it, but IE6,IE7 does not support it. IE8 starts to support it, so you need to access document.frames ['Jacks mainframe'] .document.

Compatible to get document objects:

VargetIFrameDoc=function () {

Variobj=document.createElement ("iframe")

Document.getElementsByTagName ("body") [0] .appendChild (iobj)

Returniobj.contentDocument | | iobj.contentWindow.document

}

The basic use of contentwindow:

1. Document.getElementById ("myiframe") .contentWindow. After you get the iframe object, you can get the window object of the iframe containing the page through contentWindow, and then you can access the page elements normally.

2. $("# myiframe") [0] .contentWindow. The jquery selector gets the iframe. Convert the jquery object to a DOM object first, or use the get () method to convert it.

3. $("# myiframe") [0] .contentWindow. $("# dd") .val (), you can get the window object of iframe and then use the jquery selector for page operation.

4. $("# myiframe") [0] .contentWindow.username = "zhangsan"; you can pass parameters to the iframe page in this way, and the value can be obtained in the iframe page window.username. Username is a custom global variable.

5. On the iframe page, you can get the window of the main page through parent, and then you can access the elements of the parent page normally.

6. Parent.$ ("# frame_A") [0] .contentWindow.document.getElmentById ("# frame_B"). If you call between iframe pages of the same level, you need to get the father's window first, and then call the iframe of the same level to get the window to operate.

The above is all the contents of this article "how to use contentwindow". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report