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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I pop up a confirmation box on browser exit?

    Hi everyone,
    I've been stuck on this problem for a little while now.

    Basically, I have an ASP.NET page that's holding a lot of data. In case a user accidentally clicks the exit or back button, I want to pop up a javascript confirmation box that says 'Are you sure you want to exit?' and if the user clicks 'ok', the browser exits, and if the user hits 'cancel' it returns to the page, like the user never clicked the [x].

    I can pop up a confirmation easily enough, but what methods do i need to use to keep the user or to close the browser? Also, I would like it if it only popped up on closing the browser or hitting back, not on a refresh, as the ASP page does a lot of post-backs.

    Thanks!

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    You could use a confirm box and a redirect back to the current page to handle anyone trying to leave the page but with the browser still open.

    If they close the browser window then the browser is closed and there is nothing you can run to stop it.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmmm, I thought that if I caught it with onunload() then I could do something before it exited. From what you said though, it sounds like I can do anything besides keep the browser open. Is that right?

    If so, then I'll have to somehow pull the data off the asp page and maybe serialize it and put it in a cookie. Then it should be restoreable the next time the person visits the page. I can pull it back out of the cookies and repopulate the ASP page. Does that sound like it will work?

    One other idea...could I use onunload to hit the submit button automatically when the browser exits?


  •  

    Posting Permissions

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