|
-
May 23rd, 2005, 08:24 AM
#1
Thread Starter
Fanatic Member
Stop alert message from poping up when back button is clicked.
I'm using VB .Net 2003. I have a web page where an alert button pops up if there is an error. If the user changes their criteria and clicks the submit button again then a report is created that they view. If they hit the back button, the old alert button pops up again. How can I stop this alert button from popping up again when they hit the back button?
Thanks
Last edited by indydavid32; May 24th, 2005 at 03:15 PM.
David Wilhelm
-
May 24th, 2005, 02:38 PM
#2
Thread Starter
Fanatic Member
Re: Stop alert message from poping up when back button is clicked.
-
May 24th, 2005, 03:57 PM
#3
I wonder how many charact
Re: Stop alert message from poping up when back button is clicked.
You can use javascript to remove the script if you tag it with an ID.
Code:
<script id="popAlert" type="text/javascript">
alert("Error!");
</script>
Code:
function RemoveAlert()
{
var head = document.getElementByTagName("head");
var script = document.getElementsByTagName('script');
if (script.id == "popAlert")
head[0].removeChild(script[i]);
}
-
May 24th, 2005, 04:33 PM
#4
I wonder how many charact
Re: Stop alert message from poping up when back button is clicked.
Nevermind... that won't work for history as the browser retains the document as it was.
One option then is to use Cookies. This checks to see if the cookie is there, if it is not (the first time), it pops the alert. Now, anytime after that, it won't show the alert. It of course set the cookie to expire in one day, so will have to make adjustments server-side to erase the cookie in the Response stream if they have an error.
Accessing cookies through javascript can raise alerts in browsers depending on the client's security settings.
Option two, you may have better results by sending a NO-CACHE tag to the client - which could perhaps destroy history (never tried it myself).
Your other option is to intercept the user's back and redirect them to the current document again (history.go(0) i believe).
Code:
<script type="text/javascript">
if (getCookie('srage') == null)
{
alert("Error!");
setCookie('srage','1','0');
}
function getCookie(NameOfCookie)
{ if (document.cookie.length > 0)
{ begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{ begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;
}
function setCookie(NameOfCookie, value, expiredays)
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function delCookie (NameOfCookie)
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}</script>
Last edited by nemaroller; May 24th, 2005 at 04:37 PM.
-
Apr 19th, 2008, 01:34 AM
#5
New Member
Re: Stop alert message from poping up when back button is clicked.
Pls tell me where I should give this code and how to call the alert
-
Apr 19th, 2008, 01:35 AM
#6
New Member
Re: Stop alert message from poping up when back button is clicked.
Pls tel me where I should give this code and how to call the alert
-
Apr 20th, 2008, 11:20 AM
#7
Re: Stop alert message from poping up when back button is clicked.
You could just tell the browser to not cache the page.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|