仅显示警报一次

编程入门 行业动态 更新时间:2024-10-21 13:27:05
本文介绍了仅显示警报一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个代码,它在日历中的事件发生前30分钟显示警告,但我想在用户访问页面时显示一次(在30分钟内)。现在它显示在每个页面刷新和日历刷新(在30分钟内),因为它被设置为在一段时间后刷新事件。如何只显示一次此警报?

I have this code that shows alert when it's 30 minutes before event in calendar but I want to show it only once when user comes to page (in that 30min). Now it shows on every page refresh and also on calendar refresh (in that 30min) because it is set to refresh events after period of time. How to display this alert just once?

var mili = event.start.getTime() - now.getTime(); if(mili < 1800000 && mili > 0){ $('.alert').dialog({ buttons: [{ text: "OK", click: function() { $( this ).dialog( "close" ); } }] }); }

推荐答案

您可以使用localStorage(不是与旧浏览器兼容):

You can use localStorage (not compatible with older browsers):

<script type="text/javascript"> var alerted = localStorage.getItem('alerted') || ''; if (alerted != 'yes') { alert("My alert."); localStorage.setItem('alerted','yes'); } </script>

或者你可以使用cookies,看看这个答案的完整示例代码: stackoverflow/a/21567127/3625883

Or you can use cookies, give a look to this answer for a full example code: stackoverflow/a/21567127/3625883

更多推荐

仅显示警报一次

本文发布于:2023-11-27 12:19:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638048.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!