window.location、document.location、document.URL 等区别 window.location 包含 href 属性,直接取值赋值时相当于 window.location.href。 window.location.href 当前页面完整 URL。 document.location 包含 href 属性,直接取值赋值时相当于 document.location.href。 document.location.href 当前页面完整 URL。 document.href 没有这个属性。 document.URL 取值时等价于 window.location.href 或 document.location.href。在某些浏览器中通过对 document.URL 赋值来实现页面跳转,但某些浏览器中不行。 那么 window.location 和 document.location 有什么区别呢?我认为是没有区别的,我已经在多个浏览器中不同页面(包括 iframe、frame)中测试了。有人说一个可写,一个只读,这一点也在我的测试中被否定了。同样在 MSDN 中说 location 应用于 window 和 document,但并未提出二者有区别。所以我认为二者是没有区别的。 ============================================== 实现下载的例子: 页面: document.location.target = "_blank"; var href = window.location.href.substring(0, window.location.href.lastIndexOf(".exe") + 4) + "?rm=manageBusiness&subId=downloadLog"; console.log("href:" + href); document.location.href = href;