Display warning only once

I have this code that shows a warning when it is 30 minutes before the event on the calendar, but I want to show it only once when the user comes to the page (30 minutes in advance). Now it is displayed on every page refresh, as well as in the calendar refresh (within 30 minutes), since it is configured to refresh events after a period of time. How to display this warning only once?

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

You can use localStorage (incompatible with old browsers):

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

Or you can use cookies, take a look at this answer for a complete code example: https://stackoverflow.com/a/165778/

+12
source share

Set a cookie when a warning is displayed. Then, if the cookie is set, you will know that you will not show the warning again. If it is not installed, you know that you have not yet shown a warning, and now you must do it.

You can read about setting cookies in JavaScript here.

+2
source share

To do this, you need to use cookies or localStorage or sessionStorage!

See the following link to localStorage: http://www.w3schools.com/html/html5_webstorage.asp

or

http://www.webdesignerdepot.com/2013/04/how-to-use-local-storage-for-javascript/

0
source share

All Articles