以下是JS里实现页面跳转的四种方法:
-
window.location.href= 'url': 比较常用的方法,直接跟指定要跳转的地方。
-
window.history.back(-1): 参见的浏览器返回上一个已访问的页面,直到访问最初访问的页面。
-
window.navigate("url"): navigate对象包含有关浏览器的信息,也可以作为页面跳转,后面直接加要跳转的地方。
-
top.location= 'url': 当页面中有内嵌框架时,指定最顶层的窗口跳转,及包含框架的最外层浏览器 。
示例:
要实现从一个页面A跳到另一个页面B,js实现就在A的js代码加跳转代码。
第一种:(跳转到b.html)
- <script language="javascript" type="text/javascript">
- window.location.href="b.html";
- </script>
第二种:(返回上一页面)
- <script language="javascript">
- window.history.go(-1);
- </script>
第三种:
- <script language="javascript">
- window.navigate("b.html");
- </script>
第四种:
- <script language="javascript">
- top.location=’b.html’;
- </script>