[JavaScript] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript</title>
</head>
<body>
<button>back()</button>
<button>forward()</button>
<button>go()</button>
<button>pushState()</button>
<button>replaceState()</button>
<script type="text/javascript">
function myBack(){
history.back();
}
function myForward(){
history.forward();
}
function myGo(){
var num = prompt('请输入一个整数', '1');
history.go(num);
}
function myPushState(){
var state = { 'page_id': 1, 'user_id': 5 }
var title = 'JavaScript'
var url = 'index.html'
history.pushState(state, title, url)
console.log(history.state);
}
function myReplaceState(){
var state = { 'page_id': 3, 'user_id': 5 }
var title = 'history'
var url = 'index.html'
history.replaceState(state, title, url)
console.log(history.state);
}
</script>
</body>
</html>