<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>uvi</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<button id="btn" onclick="goceshi()">按钮</buton>
<script>
function goceshi(){
history.back();
}
</script> </body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>uvi</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<a href="index9.html">跳转到index.html页面</a>
<button id="btn" onclick="">按钮</button>
<script>
function goindex9(){
history.forward();
}
</script>
</body>
</html>
下面的例子演示:点击ceshi.html的链接跳转到index10.html登陆页面,然后输入正确的用户名("hello")后又返回到之前的页面ceshi.html
即利用了history.go(-1)
ceshi.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>uvi</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<a href="index10.html">跳转到index.html页面</a> </body>
</html>
index10.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>uvi</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<form>
<input type="text" id="username">
</form>
<button id="btn" onclick="safe()">按钮</button>
<script>
function safe(){
var name = document.getElementById("username").value;
alert(username);
if(name=="hello"){
history.go(-);//回到之前的界面
}else{
alert("输入错误");
}
}
</script> </body>
</html>