<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box1{height:400px;background:#ccc;}
.box2{height:600px;background:#666;}
</style>
</head>
<body>
<div class="box1" id="top"></div>
<div class="box2"></div>
<input type="button" id="btn" value="返回顶部">
<script>
//console.log(location.href);
//console.log(location.hash);
var btn=document.getElementById("btn");
btn.onclick=function(){
location.hash="#top";
}
console.log(location.pathname);
</script>
</body>
</html>
学习目标
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="button" value="刷新" id="reload">
<script>
/* setTimeout(function(){
//location.href='index6.html';
// window.location='index6.html';
location.replace("index6.html");
},1000)*/
document.getElementById("reload").onclick=function(){
location.reload(true);
}
</script>
</body>
</html>
history对象
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="box">
请输入搜索关键字:
<input type="text" placeholder="请输入搜索关键字" id="key">
<input type="button" value="搜索" id="search">
</div>
<a href="#" id="go">跳转</a>
<script>
// 给按钮绑定事件
document.getElementById("search").onclick=function(){
// 获取搜索关键字并对它进行编码
var key=encodeURIComponent(document.getElementById("key").value);
// 跳转到指定页面
location.href='index9.html?search_key='+key;
}
var sea="搜索";
document.getElementById("go").href='index.html?key='+encodeURI(sea);
</script>
</body>
</html>
forward
Navigator对象
Screen
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>screen</title>
</head>
<body>
<script>
console.log("页面宽:"+screen.availWidth);
console.log("页面高:"+screen.availHeight);
console.log("pageWidth:"+window.innerWidth);
console.log("pageHeight:"+window.innerHeight);
</script>
</body>
</html>