. location常见方法

 

 

 

 

 

 

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

 

posted @ 2022-04-18 13:25  罗砂  阅读(167)  评论(0)    收藏  举报