我想要当页面被加载 10 次
alert ('hello !!');
如何获取?
这是我的代码:
<html>
<head>
<title>my problem !!</title>
<script type="text/javascript">
var i = 0;
myfunc = function () {
if (i++ == 10){
alert ('hello !!');
}
}
window.onload = myfunc;
</script>
</head>
<body>
</body>
</html>
谢谢你的帮助:x
最佳答案
使用 HTML 5 LocalStorage :
<html>
<script>
var visitCount = localStorage["visitCount"];
visitCount = parseInt(visitCount);
if (!visitCount) {
visitCount = 0;
}
visitCount = visitCount + 1;
if (visitCount >= 10) {
alert("hello!");
visitCount = 0;
}
localStorage["visitCount"] = visitCount;
</script>
<body>
Hi!
</body>
</html>
关于javascript - 任何时候加载页面时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14676444/