faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 22 people (55%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

which event should i capture when the browser closes using the x button.

Apr 6th, 2008 19:22
ha mo, Colin Fraser, Rohit Gupta,


There is no specific event that you can capture when a user closes the
window with a click on the x button. The button is not part of the
document, nor an accessible part of the browser. Be aware, JavaScript
has very little interaction with browser funtionality. 
However, it does not matter how a user closes the active window, the
page has to be unloaded, and that is the event you can use. Try this: 
<script>
function closing() {
    alert("You are leaving me????? ");  //put your code here
    alert("OK, be like that");
    alert("What about my dinner???");
    }
</script>
And in the <body> tag it is :  
<body onUnload="closing()">
It does not matter really, but the event is the onUnload event
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com