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

    Confirmation on Window Closing Issue

    Hi All,

    I am basically new to the web world. I would like to thank you for your time with my question, in advance.

    My issue is that, I want a confirmation box before closing my window. I have done this using the event 'onbeforeunload'. It works fine , but the problem is that, the event is been generated when I move to next page or refresh the same page. I want this confirmation only when closing the window.

    The code goes like this
    ***********************
    <html>
    <head>
    <title>Testing</title>
    <script language="JavaScript">
    <!--
    window.onbeforeunload = bunload;

    function bunload(){
    dontleave="Are you sure you want to leave?";
    return dontleave;
    }
    //-->
    </script>
    </head>

    <body>
    Please stay on this page!
    </body>


    </html>

    ***********************

    Please help me,

    Thank You
    Subeesh.K.K

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    it should be:

    Code:
    window.onbeforeunload = bunload();
    thats all I can see

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    @IrDewey: Actually, this line is just fine as is and your "correction" is wrong.

    @OP: Try using confirm:
    Code:
    <html>
      <head>
      	<title>Testing</title>
      	<script language="JavaScript">
      	<!--
      		window.onbeforeunload = bunload;
      		
      		function bunload(){
      		dontleave=window.confirm("Are you sure you want to leave?");
      		return (dontleave !== false);
      	}
      	//-->
      	</script>
      </head>
    
      <body>
      Please stay on this page!
      </body>
    </html>
    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by subeeshkk View Post
    the problem is that, the event is been generated when I move to next page or refresh the same page. I want this confirmation only when closing the window.
    Impossible with javascript. From the javascript interpreter's point of view all the actions like: navigating to another domain, navigating to another page on the same domain, refreshing, closing the tab, closing the window... all these mean nothing but a single action: closing the session.

    A server-side application is able to be a little bit sensitive, as it can make the difference between inner domain (internal session) and outer domain navigation, but that will be all. Nor a server-side application can differentiate between leaving a domain and closing the tab/window/browser.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    confirm window

    I need confirmation only onexit windows but this code dosent let me to submit my form


  •  

    Posting Permissions

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