We help IT Professionals succeed at work.

How to have javascript alert run only once

sunny012097
sunny012097 asked
on
2,613 Views
Last Modified: 2013-11-05
Hello experts,

I am using registerclientscript in asp.net to pop up an elert message. It works fine. My problem is, when I browse to another page and click back on my browser that script runs again. I was wondering if there is a way to run the alert only once so that if a user clicks the back button of the browser they don't see the alert message again.

Thanks.
Comment
Watch Question

i'd say not
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
if(cookie==not visited) {alert('Hello handsome')]
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
to delete a cookie if you don't need then call the deleteCookie function as

deleteCookie("isAlerted");

that's all
another simple solution is to use session variable to set whether the alert message is shown or not.
so whenever the user comes to this page, the session variable's value will be checked and the alert message is shown is not already shown.

this will be helpful when the user has disabled cookies.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
actually we can delete cookies by setting the expiry time. here in the example when the user closes the browser, the cookie will be automatically deleted. so when the user comes back to the page again, the alert Message will be shown, because the cookie will not be present.

Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.