<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>历史记录</title>
</head>
<body>
<input type="button" onclick="add()" value="添加一个历史记录">
<script>
function add() {
//判断浏览器是否支持这个API
if (window.history && history.pushState) {
//支持
history.pushState('数据','设置历史状态显示的标题,但是浏览器不支持','?demo=' + new Date().toLocaleTimeString());
//new Date()获取的是一个时间对象,
//toLocaleTimeString转换成我们能认识的时间字符串
//toLocalDateString转换成我们能认识的日期字符串
} else {

}
}
window.addEventListener('popstate',function(e) {
//后退或前进操作
console.log('1111' + e.state);
})
</script>
</body>
</html>
posted on 2018-08-21 23:27  一步一个脚印,一直走着  阅读(201)  评论(0编辑  收藏  举报