IE Bug (window === top) === false

前端 未结 4 632
温柔的废话
温柔的废话 2020-12-01 12:59

In IE.

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

In FF3.6 & Chr

4条回答
  •  执念已碎
    2020-12-01 13:27

    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.

    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.

提交回复
热议问题