HTML 页面跳转

标签定时跳转

<head>
<!-- 以下方式只是刷新不跳转到其他页面 -->
<meta http-equiv="refresh" content="10">
<!-- 以下方式定时转到其他页面 -->
<meta http-equiv="refresh" content="5;url=hello.html"> 
</head>

使用location跳转

  • location是最有用的BOM对象之一。
  • window.location 和 document.location 引用的使用一个对象。
//三者效果完全一样
location.assign("www.baidu.com");
location.href = "www.baidu.com";
window.location = "www.baidu.com";

//导致浏览器位置改变,但不会在历史记录中生成新纪录,用户不能反悔前一个页面。
location.replace("www.baidu.com");

//重新加载当前页面
location.reload(); //有可能从缓存中加载
location.reload(true); //从服务器重新加载

//假定初始的URL为http://www.baidu.com/WileyCDA

//将URL修改为 http://www.baidu.com/WileyCDA/#section1
location.hash = "#section1";

//将URL修改为 http://www.baidu.com/WileyCDA/?name=kaifa
location.search = "?name=kaifa";

//将URL修改为 http://www.google.com/WileyCDA
location.hostname = "www.google.com";

//将URL修改为 http://www.baidu.com/fafa
location.pathname = "fafa";

//将URL修改为 http://www.baidu.com:8080/WileyCDA
location.port = 8080;

猜你喜欢

转载自blog.csdn.net/weixin_42950052/article/details/81914339