sunny012097
asked on
How to have javascript alert run only once
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.
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.
i'd say not
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if(cookie==not visited) {alert('Hello handsome')]
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
to delete a cookie if you don't need then call the deleteCookie function as
deleteCookie("isAlerted");
that's all
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.