Results 1 to 8 of 8

Thread: capturing close event of browser

  1. #1

    Thread Starter
    Hyperactive Member jeba's Avatar
    Join Date
    Feb 2000
    Posts
    265

    capturing close event of browser

    Hi there!
    In Unload event of the window, is it possible to capture if the user clicked the 'x' button of the browser window?

    Thanks in advance.
    J£ßä

  2. #2
    Addicted Member tonyenkiducx's Avatar
    Join Date
    Oct 2000
    Location
    London England
    Posts
    147
    If you mean in ASP, no(Well, you can tell if a user left your site, but not if they clicked that particular button). If you mean VB, of course, its the form_unload event...

    Tony

  3. #3

    Thread Starter
    Hyperactive Member jeba's Avatar
    Join Date
    Feb 2000
    Posts
    265

    in Javascript..

    Hi there!
    I wanted to capture it in Javascript..

    Thanx for your reply.
    J£ßä

  4. #4
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    i tried it once.. in the body tag

    Can't remember the exact code... it worked, but if you refresh the screen it also fires the function.

    I will have too search for it somewhere on my HDD.

  5. #5
    Matthew Gates
    Guest
    <body onUnload="javascript:alert('You are closing the window. Bye!')">

    java script <-a space is added, just make it one word.
    Has something to do with the coding, John says it's for security reasons .

  6. #6

    Thread Starter
    Hyperactive Member jeba's Avatar
    Join Date
    Feb 2000
    Posts
    265
    Hi there!
    Thanx for the replies.
    Matthew!
    Your code executes when I submit the page to another page also.
    I want the code to run only when the user closes the form using the 'x' button of the browser.

    Regards,
    J£ßä

  7. #7
    Addicted Member tonyenkiducx's Avatar
    Join Date
    Oct 2000
    Location
    London England
    Posts
    147
    Like I said before, there is no javascript support for window functions..

    Think about it, javascript works on any OS, from palm pilots, to sun microstations, so it cant contain code to handle clicking the X, expecially when on some OS's there is no X button(Palm OS for example)

    Another thought does come to mind though.. if you close a window the window.location.href value is altered immediately to show the URL of the link you clicked on, so if inside the unload tag you put some code to check the href of the current page(Youll have ot hard code that into the HTML, or do it with ASP) against the window.location.href value, if there the same, then the page is just being closed, if its changed, then the page is obviously going elsewhere..

    Dammit Im good hehe

  8. #8
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: capturing close event of browser

    Originally posted by jeba
    Hi there!
    In Unload event of the window, is it possible to capture if the user clicked the 'x' button of the browser window?

    Thanks in advance.
    Don't know if you have found your answer but this works...

    Code:
    <SCRIPT LANGUAGE=javascript FOR=window EVENT=onunload>
    <!--
    	window_onunload()
    //-->
    </SCRIPT>
    <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
    <!--
    
    function window_onbeforeunload() {
    	event.returnValue = "Any changes made will now be saved.";
    	
    }
    
    function window_onunload() {
    	if(window.event.returnValue = true){
    		
    	}
    }
    
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE=javascript FOR=window EVENT=onbeforeunload>
    <!--
     window_onbeforeunload()
    //-->
    </SCRIPT>

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