|
-
Jun 12th, 2001, 09:34 AM
#1
Thread Starter
Hyperactive Member
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.
-
Jun 12th, 2001, 10:13 AM
#2
Addicted Member
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
-
Jun 12th, 2001, 11:44 PM
#3
Thread Starter
Hyperactive Member
in Javascript..
Hi there!
I wanted to capture it in Javascript..
Thanx for your reply.
-
Jun 13th, 2001, 02:04 AM
#4
Lively Member
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.
-
Jun 13th, 2001, 02:10 AM
#5
<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 .
-
Jun 13th, 2001, 06:31 AM
#6
Thread Starter
Hyperactive Member
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,
-
Jun 13th, 2001, 06:36 AM
#7
Addicted Member
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
-
Nov 19th, 2002, 03:50 PM
#8
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|