前端网页设计
设计网页访问次数
JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
if(null !=localStorage.pagecount){
localStorage.pagecount=Number(localStorage.pagecount)+1;
}else{
localStorage.pagecount=1;
}
document.write("已经访问了"+localStorage.pagecount+"次<br>");
</script>
此方法可以没有时间限制,即使关闭浏览器次数不会刷新
还有另一种方法,关闭浏览器就会刷新
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
if(sessionStorage.pagecount){
sessionStorage.pagecount=Number(sessionStorage.pagecount)+1;
}else{
sessionStorage.pagecount=1;
}
document.write("已经访问了:"+sessionStorage.pagecount+"次");
</script>