创建不受页面刷新影响的计时器或警报
我想在我的网站中创建一个计时器/警报,提示用户距离您登录已经过去 1 小时了。 刷新页面时计时器不应从头开始。我尝试使用
setTimeout(function(){
alert('signout!!');
}, 10000);
只要不刷新页面它就可以正常工作。欢迎任何想法。有没有办法从db计算时间?我将登录时间存储在数据库中。
谢谢
I want to create a timer/alert in my website that prompts the user that its 1 hour since you logged in.
The timer shouldn't start from beginning when the page is refreshed. I tried using
setTimeout(function(){
alert('signout!!');
}, 10000);
It works fine as long as I don't refresh the page. Any ideas are welcome. Is there any way to calculate the time from db? Im storing the log in time in db.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 cookie 来存储开始时间。在页面加载时,您可以检查 cookie,并相应地设置计时器。
当计时器到达小时标记时,或者如果页面在到达该标记后加载,则提示用户并删除 cookie。
要在 Javascript 中设置 cookie,请查看此页面:
http://www.w3schools.com/js/js_cookies.asp
Use a cookie to store a start time. On page load you can check for the cookie, and set your timer accordingly.
When the timer hits the hour mark, or if the page loads after the mark has been reached, prompt the user and delete the cookie.
To set cookies in Javascript, check out this page:
http://www.w3schools.com/js/js_cookies.asp
将您的计时器与特定的日期/时间联系起来——在页面加载时,找出到未来该点为止剩余的秒数,并相应地设置超时。您可以在客户端或服务器上完成工作。无论哪种方式。
Tie your timer to a specific date/time -- on page load, find out the number of seconds remaining until that point in the future, and set your timeout accordingly. You can do the work on the client or server. Either way.
我得到了这样的解决方案。
在
标签中
然后在正文中
I got the solution like this.
In
<head>
tagThen in the body