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.
Printable View
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.
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
Hi there!
I wanted to capture it in Javascript..
Thanx for your reply.
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.
<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 :rolleyes:.
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,
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
Don't know if you have found your answer but this works...Quote:
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.
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>