Results 1 to 7 of 7

Thread: Stop alert message from poping up when back button is clicked.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Unhappy 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

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Re: Stop alert message from poping up when back button is clicked.

    Bump
    David Wilhelm

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    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]);
    }

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    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.

  5. #5
    New Member
    Join Date
    Apr 2008
    Posts
    2

    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

  6. #6
    New Member
    Join Date
    Apr 2008
    Posts
    2

    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

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width