window location跳转的几种方式与a链接跳转的总结

发布时间 2023-04-18 16:52:04作者: 一统天下。

1.window.location.href 在当前页面跳转

window.location.href = 'http://www.baidu.com' 等于 <a href="http://www.baidu.com"></a>

2.window.open 在新页面跳转

window.open('www.baidu.com') 等于 <a href="http://www.baidu.com" target="_blank"></a>

3.self.location.href =‘www.baidu.com’ 禁止页面跳转-可以用在你页面要打开外部插件

self.location.href ='www.baidu.com' 等于 <a href="www.baidu.com" target="_self"></a>

4.window.location.assign() 也是在本页面刷新

5.window.location.reload(true);强制从服务器重新加载当前页面 

6.window.location.replace()重新加载页面