<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>页面跳转</title>
    <script>
        function app() {
            window.location.assign('http://www.baidu.com');
        }
    </script>
</head>
<body>
    <input type="button" value="页面跳转" onclick="app()" />
</body>
</html>

其中window.location.assign(url)window.location.href=url实现功能是一样的,都是跳转到网址,只是用法稍微不同。最大的不同是,window.location.assign(url)会添加记录到浏览历史,点击后退可以返回之前页面,而window.location.href=url则不行。

  • window.location.href= 'url': 比较常用的方法,直接跟指定要跳转的地方。

  • window.history.back(-1);: 参见的浏览器返回上一个已访问的页面,直到访问最初访问的页面。

  • window.navigate("url");: navigate对象包含有关浏览器的信息,也可以作为页面跳转,后面直接加要跳转的地方。

  • top.location= 'url';: 当页面中有内嵌框架时,指定最顶层的窗口跳转,及包含框架的最外层浏览器 。

第一种方式
  1. <script language="javascript" type="text/javascript">
  2. window.location.href="a.html";
  3. </script>
第二种方式
  1. <script language="javascript">
  2. window.history.go(-1);
  3. </script>


第三种方式
  1. <script language="javascript">
  2. window.navigate("b.html");
  3. </script>


第四种方式
  1. <script language="javascript">
  2. top.location=’b.html’;
  3. </script>
 
 
 

  

 

posted on 2021-08-10 21:31  前端学习/vue  阅读(334)  评论(0编辑  收藏  举报