What's the difference between [removed] and [removed] in JavaScript?

后端 未结 16 1970
故里飘歌
故里飘歌 2020-11-22 12:37

Should both of them reference the same object?

相关标签:
16条回答
  • 2020-11-22 13:18

    Actually I notice a difference in chrome between both , For example if you want to do a navigation to a sandboxed frame from a child frame then you can do this just with document.location but not with window.location

    0 讨论(0)
  • 2020-11-22 13:21

    document.location.constructor === window.location.constructor is true.

    It's because it's exactly the same object as you can see from document.location===window.location.

    So there's no need to compare the constructor or any other property.

    0 讨论(0)
  • 2020-11-22 13:22

    According to the W3C, they are the same. In reality, for cross browser safety, you should use window.location rather than document.location.

    See: http://www.w3.org/TR/html/browsers.html#dom-location

    0 讨论(0)
  • 2020-11-22 13:22

    Well yea, they are the same, but....!

    window.location is not working on some Internet Explorer browsers.

    0 讨论(0)
  • 2020-11-22 13:24

    Yes, they are the same. It's one of the many historical quirks in the browser JS API. Try doing:

    window.location === document.location
    
    0 讨论(0)
  • 2020-11-22 13:25

    window.location is read/write on all compliant browsers.

    document.location is read-only in Internet Explorer (at least), but read/write in Gecko-based browsers (Firefox, SeaMonkey).

    0 讨论(0)
提交回复
热议问题