I tried to make a function that displays an alert on the 1st page load <body onload="alertbox()>", and its working on 2nd page load instead of 1st. What should i use instead of "onload" to make it work only on 1st load?
I'm beginner, sorry if it's a dumb question.
var alertboxStatus = localStorage.getItem("alertbox", alertboxStatus);
localStorage.setItem("alertbox", alertboxStatus)
function alertbox()
{
if (alertboxStatus == "null" || alertboxStatus == "")
{
alert("Alert!");
alertboxStatus = "displayed";
localStorage.setItem("alertbox", alertboxStatus);
}
};
I also tried this:
But it's also working on second page load. Am i doing sth wrong with locationStorage.setItem?
document.addEventListener('DOMContentLoaded', function ()
{
if (alertboxStatus == "null" || alertboxStatus == "")
{
alert("alert");
alertboxStatus = "displayed";
localStorage.setItem("alertbox", alertboxStatus);
}
}, false);
Changing "null" to null worked