關閉時的方法:

function window.onunload()

{

alert("窗體關閉了!");

}
如果需要在關閉前給使用者關閉提示,而且想在使用者點選浏覽器關閉按鈕關閉時,也隻有用以下的方法才能在退出時,執行事件:

function window.onbeforeunload()
{
if( event.clientX>document.body.clientWidth && event.clientY<0 || event.altKey )
window.event.returnValue="确定要退出本頁嗎?";
}