文件下载中使用到了document.location

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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值