Answer the question
In order to leave comments, you need to log in
How can I make the alert only appear on the first page load?
How can I make the alert only appear on the first page load? So that when you go to other pages, and then back to the main one, alert does not appear.
<script>
function hello()
{
alert("Вітаю вас на головній сторінці!")
}
</script>
<body onLoad="hello()">
Answer the question
In order to leave comments, you need to log in
Write to localstorage, for example:
And check
if (localStorage.getItem("greeted") !== true)
alert("Вітаю вас на головній сторінці!")
getCookie(name)
and setCookie(name, value, options)
can be peeped in the article about cookies .
Add an entry to the cookie, on the first visit, and check for its existence. If there is no record, we display a message and set the cookie, if there is, we do nothing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question