IE Bug(窗口===顶部)=== false [英] IE Bug (window === top) === false

查看:159
本文介绍了IE Bug(窗口===顶部)=== false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE中。

window === top; // false
window === window.window // false
window == top; // true
window == window.window // true

在FF3.6& ; Chrome稳定不会发生这种情况。

In FF3.6 & Chrome stable this doesn't happen.

在IE typeof .toString Object.prototype.toString.call 对于 top & window

In IE typeof, .toString, Object.prototype.toString.call all return the same for both top & window

这与这个

谁能告诉我为什么IE不能做严格的平等?

Can anyone tell me why IE can't do strict equivelance?

请注意,循环引用不会导致IE和& Chrome。

Note that circular reference doesn't cause issues in both IE & Chrome.

o = {};
o.o = o;
o === o.o; // true

结果

window.window === window.top; // true
window.window === window.self; // true

因此获取窗口的问题 on the own。

So it's an issue with getting window on it's own.

for (var i in window) {
    if (window.window[i] !== window[i]) {
        console.log(i); // external, frames, clipboardData
    }
}

现在这只是愚蠢:

 window.frames === window.frames; // false
 window.frames == window.frames; // false
 window.external == window.external; // true
 window.external === window.external; // false
 window.clipboardData === window.clipboardData; // false
 window.clipboardData == window.clipboardData; // false

[进一步编辑]

结果是window.frames保存了指向ie调试器的指针。因此,打开调试器会更改窗口对象。我必须做更多的测试。

turns out that window.frames holds a pointer to the ie debugger. So having the debugger open changes the window object. I have to do some more testing.

window.frames.location === window.frames.location; // false
window.frames.location == window.frames.location; // true
window.frames.event.boundElements == window.frames.event.boundElements; // false

更不用说 window.external 只是不能很好地播放

Not to mention that window.external just does not play nicely

>>for (var i in window.external) alert(i);
"Object doesn't support this action"


推荐答案

这不是一个错误:主机对象可以做任何他们喜欢的事情,窗口对象是一个特别复杂的野兽,服务于作为对象的双重目的表示浏览器窗口,也是全局对象的别名。我会把这个作为一个奇怪的东西,并避免在比较 Window 对象时使用严格的 === 运算符。

This isn't exactly a bug: host objects can do whatever they like, and the window object is a particularly complicated beast, serving the dual purposes of being the object that represents the browser window and also being an alias for the global object. I'd chalk this one up as a weirdness and avoid using the strict === operator when comparing Window objects.

请注意,这不是JavaScript很奇怪的耸耸肩。除了作为全局对象之外,窗口是一个主机对象,并且HTML5之前可以合法地(至少根据规范)表现出它喜欢的行为。较早版本的IE利用了这种自由,表现出许多古怪的行为,没有任何规范。试图在不访问源代码的情况下理解它是一个毫无意义的练习。

Note that this isn't a "JavaScript is weird" shrugpost. As well as serving as the global object, window is a host object and pre-HTML5 could legitimately (according to spec, at least) behave however it liked. Older versions of IE take advantage of this freedom and exhibit much quirky behaviour for which there is no specification whatsoever. Trying to understand it all without access to the source code is a pointless exercise.

这篇关于IE Bug(窗口===顶部)=== false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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