为什么窗口不同于window.self在Internet Explorer中? [英] Why is window not identical to window.self in Internet Explorer?

查看:243
本文介绍了为什么窗口不同于window.self在Internet Explorer中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个复杂的背景故事涉及我如何碰到这个,但为什么 self 属性不完全等于窗口本身?

There's a convoluted backstory involving how I came across this, but why is the self property not exactly equal to the window itself?

在Safari和Firefox和朋友中,结果是我预期的:

In Safari and Firefox and friends, the results are as I'd expect:

> window == window.self
  true
> window === window.self
  true

,但:

>> window == window.self
   true
>> window === window.self
   false

任何人都可以解释不一致?到底是什么是窗口对象的 self 属性指向?

Can anybody account for the inconsistency? To exactly what is the self property of the window object pointing? It casts to something with equality, which is even more vexing.

推荐答案

这不是全部,窗口! == window.window

我相信我们可能看到的是'内窗口'和'外窗口'对象。当然,其他浏览器也有这些(例如 Moz );它们通常用于表示自己代码内部和外部的窗口的不同视图。

I believe what we're probably seeing here is the difference between the ‘inner window’ and ‘outer window’ objects. Certainly other browsers have these (eg. Moz); they're typically used to present a different view of the window from inside and outside its own code.

内部窗口保存您的全局变量和特定于文档的成员。外部窗口可通过 frames [n] 等窗口引用访问[cross-frame- , opener ,显然 self 。它绑定到所有者视口(浏览器窗口/框架),因此例如。当您将iframe导航到新文档时,父文档仍然在其iframe中看到相同标识窗口对象。

The inner window holds your global variables and document-specific members. The outer window is accessible to [cross-frame-] scripting via window-references like frames[n], parent, opener, and apparently self. It is bound to the owner viewport (browser window/frame), so eg. when you navigate an iframe to a new document, the parent document still sees the same-identity window object in its iframe.

在一个明智的浏览器对象模型设计中,会有单独的对象,但是当JavaScript最初由Netscape投射在一起时,几乎没有考虑优雅,导致这个和许多其他界面有过多的重载(提交的元素形成,任何人?)。

In a sensible Browser Object Model design there would be separate objects for this, but when JavaScript was originally thrown together by Netscape there was very little consideration for elegance, resulting in this and many other interfaces where there is too much overload (form with an element called submit, anyone?).

为了兼容性,分割窗口必须继续出现为脚本的单个对象,即使它不在下面。在IE中,有时面具滑动:看起来像窗口得到你的内部窗口,没有黑客,使它 === 对外窗口。

So for compatibility, the split window has to continue to appear to be a single object to scripts even though it isn't underneath. In IE, sometimes the mask slips: it seems like saying window gets you the inner window, and there's no hack to make it === against the outer window.

ETA:实际上想到它,甚至有一些(穷)的理由。 ECMAScript规范并未考虑多个全局上下文,定义 window 和未绑定版本 this ,作为检索全局变量scope对象,这将是内部窗口。

ETA: Actually come to think of it, there's even some (poor) justification for this. The ECMAScript spec, which is not written with multiple global contexts in mind, defines window, and the unbound version of this, as retrieving the global variable scope object, which would be the inner window.

其他属性,作为DOM / BOM的一部分,不在ECMA规范,所以他们可以返回不同的东西(为了跨帧脚本的目的,必须)。

The other properties, being part of the DOM/BOM, are not within the scope of the ECMA spec, so they can return something different (and must, for the sake of cross-frame scripting).

这篇关于为什么窗口不同于window.self在Internet Explorer中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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