contentDocument和contentWindow javascript iframe / frame访问属性之间的区别 [英] Difference between contentDocument and contentWindow javascript iframe/frame access properties

查看:158
本文介绍了contentDocument和contentWindow javascript iframe / frame访问属性之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 这两个属性(contentDocument和contentWindow)有什么区别?

  • 他们访问$ b中内容的方式有什么不同吗? $ b frame / iframe?

  • 是否有任何性能问题?

  • 我应该使用 contentXXXXX.document.getElementsBy .. 。
    contentXXXXX.getElementsBy ...

  • What is the difference between these two properties (contentDocument and contentWindow)?
  • Is there any difference in the way they acces the content in the frame/iframe?
  • Is there any performance issues?
  • Should I use contentXXXXX.document.getElementsBy... or contentXXXXX.getElementsBy...?

我一直在网上搜索,但没有找到太多的信息,在我做了大量研究之前,我想我可以在stackoverflow问这个伟大的社区。作为评论,我正在编写一个脚本来计算网页上的输入,访问所有级别的帧或iframe,并将帧/ iframe中找到的输入添加到全局计数中。所有内容都应该来自同一个域名,所以我认为不应该存在同源政策的问题。对于脚本我使用纯JavaScript没有jQuery或任何使生活更轻松的框架/库u_u jaja。这是一个练习脚本,如果有人想看看我发布的代码,没问题。感谢任何花时间解释这一点的人!

I've been searching around in the web but haven't found too much information and before I did a big research I thought I could ask the great community here at stackoverflow. As a comment I'm doing a script that counts inputs on a web page, accessing all levels of frames or iframes and adding those inputs found inside the frames/iframes to the global count. All content is supposed to be from the same domain so no there should be no problems with same-origin-policy, I believe. For the script I'm using pure JavaScript no jQuery or any frameworks/libraries that make life easier u_u jaja. This is a practice script and if anyone would like a look at the code I'll post it, no problem. Thanks for anyone who takes the time to explain this!

推荐答案

我认为 < iframe> MDN文档解释得很好:

I think the <iframe> MDN documentation explains it well:


从DOM iframe 元素,脚本可以访问 window 通过 contentWindow 属性包含的HTML页面的对象。 contentDocument 属性引用 iframe 中的文档元素(这相当于 contentWindow.document ),但IE8之前的Internet Explorer版本不支持。

From the DOM iframe element, scripts can get access to the window object of the included HTML page via the contentWindow property. The contentDocument property refers to the document element inside the iframe (this is equivalent to contentWindow.document), but is not supported by Internet Explorer versions before IE8.

所以你要使用 contentWindow ,就像你使用窗口 contentDocument 当你使用 document

So you would use contentWindow the same way you use window and contentDocument as you use document.

这篇关于contentDocument和contentWindow javascript iframe / frame访问属性之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆