【问题标题】:javascript - window.location or document.location [duplicate]javascript - window.location 或 document.location [重复]
【发布时间】:2013-02-11 14:24:25
【问题描述】:

window对象的location属性和document对象的location属性有什么区别吗?

window.location || document.location  // That is the question.
  • 它们的属性是否相同?
  • 它们有不同的浏览器支持吗?

【问题讨论】:

标签: javascript object browser


【解决方案1】:

这两个对象是相同的:

console.log(window.location === document.location) // true

它们都引用 Location 对象。

【讨论】:

  • 为什么有两种方法可以访问同一个对象?
【解决方案2】:
window.location represent position in current view of page in browser window

document.location代表当前显示完整文档/页面的位置

例如在http://www.nationalgeographic.com/ 每日新闻部分是window,向下滚动到最后的整页是document

【讨论】:

    猜你喜欢
    • 2011-01-26
    相关资源
    最近更新 更多