Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts

    prompt before allowing back button

    I need to find a way, so that if the user clicks the back button on the browser, i can prompt them, and potentialy disallow the use of the back button.

    *Click back button*
    Are you sure you want to go back? Data will be lost!
    *Click cancel*
    The page dosnt change.

    If anyone knows how i can do this, plz inform.
    If I'm postin here, I NEED YOUR HELP!!

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Cannot be done reliably.
    Sorry.

    You can put code in the onunload of the page to TRY, but it doesn't always fire.
    You can try to remove the back button, but I have keyboard shortcuts to go back and my right-click menu.
    You can try to take that away, but I have a quick bookmarklet to get it back b/c it really irritates me when people do that.

    So, you can try to save the user from himself/herself, but your best bet is to inform them in plain text at the top of the page...
    IF YOU LEAVE THIS PAGE WITHOUT SAVING (INCLUDING HITTING BACK BUTTON) YOUR DATA WILL BE LOST.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •