如何从Document对象获取Window对象? [英] How do I get the Window object from the Document object?

查看:269
本文介绍了如何从Document对象获取Window对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以得到window.document,但我怎样才能得到document.window?我需要知道如何在所有浏览器中完成它。

com / HTMLDOM / dom_obj_window.asprel =nofollow noreferrer> Window对象是JavaScript层次结构中的顶级对象,因此只需将其称为窗口



编辑
促进JS 的努力之前的原始答案。 Mozilla开发者网络上的JavaScript技术概述说:


在浏览器环境中,此全局对象是窗口对象。


编辑2:
在阅读作者对他的问题的评论(并获得降低评分)之后,这似乎与iframe的文档窗口有关。看看 window.parent window.top ,或许可以比较它们来推断您的文档窗口。

  if(window.parent!= window.top){
//我们比一个更深
}


I can get window.document but how can I get document.window? I need to know how to do it in all browsers.

解决方案

The Window object is the top level object in the JavaScript hierarchy, so just refer to it as window

Edit: Original answer before Promote JS effort. JavaScript technologies overview on Mozilla Developer Network says:

In a browser environment, this global object is the window object.

Edit 2: After reading the author's comment to his question (and getting downvotes), this seems to be related to the iframe's document window. Take a look at window.parent and window.top and maybe compare them to infer your document window.

if (window.parent != window.top) {
  // we're deeper than one down
}

这篇关于如何从Document对象获取Window对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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