<!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';: 当页面中有内嵌框架时,指定最顶层的窗口跳转,及包含框架的最外层浏览器 。
第一种方式
- <script language="javascript" type="text/javascript">
- window.location.href="a.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>