1.URL
2.location对象的属性
案例:5秒后跳转到新页面
代码如下:
<body>
<button>点击</button>
<div></div>
<script>
var btn = document.querySelector('button');
var div = document.querySelector('div');
var time = 5;
var timer = function() {
if (time == 0) {
location.href = 'http://www.baidu.com';
} else {
div.innerHTML = '您将在' + time + '秒后跳转到首页';
time--;
}
}
timer();
setInterval(timer, 1000)
</script>
</body>
3.location对象的方法
- location.assign()记录浏览历史,可以回退
- location.replace()不记录浏览历史,不能回退
- location.reload()刷新页面
4.navigator对象
5.history对象
案例:获取url参数
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<a href="list.html">点击我去往列表页</a>
<button>前进</button>
<script>
var btn = document.querySelector('button');
btn.addEventListener('click', function() {
//前进
//history.forward();
//前进一步
history.go(1);
})
</script>
</body>
</html>
list.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<a href="index.html">点击我返回首页</a>
<button>后退</button>
<script>
var btn = document.querySelector('button');
btn.addEventListener('click', function() {
//history.back();
//后退一步
history.go(-1);
})
</script>
</body>
</html>