0
<script>alert('Hai Jangan lupa klik tombol Refresh!(Ok Untuk Lanjutkan)');</script>

when I refresh my website the alert notification keeps popping up, I only want the alert to appear only once when the web is first opened

Barmar
  • 669,327
  • 51
  • 454
  • 560
  • When you refresh your site, that is the one time the alert message would appear. You're saying you'd want that alert message to appear ONLY on the first time someone visits the page, and then never again? – Musilix Jan 12 '22 at 04:19
  • Use a cookie or localStorage to remember if you already displayed the alert. – Barmar Jan 12 '22 at 04:20

2 Answers2

2

A simple flag is what you need.

if(window.localStorage.getItem("visited")){
    alert("something");
    window.localStorage.setItem("visited", true)
}

Depending on what you want to setup the scope of the storage, you can checkout localStorage, sessionStorage or cookies What is the difference between localStorage, sessionStorage, session and cookies?

Yash Kumar Verma
  • 8,887
  • 2
  • 15
  • 28
1

You can use localStorage and check if the alert has already popup.

if (localStorage.getItem('__isAlert') !== "show") {
  localStorage.setItem("__isAlert", "show");
  alert("Hai Jangan lupa klik tombol Refresh!(Ok Untuk Lanjutkan");
}
Sahid Hossen
  • 1,127
  • 10
  • 14