faqts : Computers : Programming : Languages : JavaScript : Event handling

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

56 of 142 people (39%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How can I capture the window.close() event other then ONUNLOAD?

Feb 19th, 2006 11:09
Alex Cohn, Adam Baruch,


You can add two lines to your script:
    function window_close() { alert("I shall not close"); }
    window.close = window_close;
Now call to window.close() will show the new alert. You can store the
original function aside, e.g. 
    var backup = new Object(); backup.close = window.close;
(naturally, you do that before you reassign window.close). Now you can
perform all your verification and call the orignal function to close the
window.