码迷,mamicode.com
首页 > Windows程序 > 详细

HTML5之历史记录API

时间:2018-08-22 00:22:43      阅读:421      评论:0      收藏:0      [点我收藏+]

标签:cli   char   history   标题   win   html   否支持   test   设置   

<!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>

HTML5之历史记录API

标签:cli   char   history   标题   win   html   否支持   test   设置   

原文地址:https://www.cnblogs.com/zlinger/p/9515152.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!