SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there a javascript function that will...

    Is there a javascript function that when you press the close button at the top right hand corner of your browers will prompt you and say:

    Are you sure you want to close:

    yes or no

    Thanks.

  2. #2
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,727
    Mentioned
    43 Post(s)
    Tagged
    0 Thread(s)
    There's such a thing as an "onunload" event.

    You can have "window.onunload", which will be triggered when the window is closed.




    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way to disable the exit or back button then?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    Virginia
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <title>test</title>
    <script language="javascript" type="text/javascript">
    window.onbeforeunload = keep_open;
    
    function keep_open(){
    	return "Are you sure you'd like to exit this page?";
    }
    </script>
    </head>
    <body>
    MY WEB SITE!!!!
    </body>
    </html>
    Mark A. Drake
    - Mark A. Drake
    - OnSlaught

  5. #5
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,727
    Mentioned
    43 Post(s)
    Tagged
    0 Thread(s)
    window.onbeforeunload...

    Well I can't say I knew about that one.




    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  6. #6
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,727
    Mentioned
    43 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wickedneat
    Is there a way to disable the exit or back button then?
    What the hell are you up to??

    To disable the back button, all I can think of is to launch a new window or have some blank intermediary page that redirects to the final page, so that if someone clicks "back" they'd return to the blank page and it'd kick them back to your final page regardless.

    Of course if they click back multiple times they'd probably get around it.




    Last edited by Shaun(OfTheDead); Aug 1, 2007 at 04:46. Reason: typo
    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  7. #7
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,727
    Mentioned
    43 Post(s)
    Tagged
    0 Thread(s)
    I don't think there's a way to disable the exit button, though. It'd be too much of a security risk.




    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    Virginia
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shaun(OfTheDead) View Post
    window.onbeforeunload...

    Well I can't say I knew about that one.




    =D
    Mark A. Drake
    - Mark A. Drake
    - OnSlaught


Bookmarks

Posting Permissions

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