I’m having a problem relating to storing a variable within Javascript. I have a web monitoring page (I have written the code which works), which refreshes automatically every 5 mins.
If one of the sites I am monitoring goes down, the JS sends an email to the admin, but I only want to send this once.
My logic was to:
Check if a site is down
if variable emailPreviouslySent == ‘no’
then send email to admin
write to variable emailPreviouslySent = ‘yes’Page would refresh
Check if a site is down
emailPreviouslySent == ‘yes’email would not be sent again
However I’m finding that the variable is emptied each time the page refreshes.
Is there a way of carrying the variable even though the page is refreshing, or perhaps another way around this?
Thanks for your help.
You are inside state-less HTTP request. Store your variable in cookie to retain its value even after page refresh but notice that a cookie can be deleted by a user too.
Or as rightly suggested by @Matt Ball, a better approach would be to use HTML5’s
localStoragefeature.