location对象方法
返回值
location.assign()
跟href -样,可以跳转页面(也称为重定向页面)
location.replace()
替换当前页面,因为不记录历史,所以不能后退页面
location.reload()
重新加载页面,相当于刷新按钮或者f5如果参数为true强制刷新ctrl+f5
- <button>点击跳转</button>
- <script>
- var btn = document.querySelector('button');
- btn.addEventListener('click', function() {
- //记录浏览历史,所有可以现实后退功能
- location.assign('http://www.zidiu.com');
- //不记录浏览历史,所以不能实现后退功能
- location.replace('http://www.zidiu.com');
- });
- </script>
复制代码 |
|