代碼如下:
<script type="text/javascript">
window.onbeforeunload = onbeforeunload_handler;
window.onunload = onunload_handler;
function onbeforeunload_handler(){
var warning="確認退出?";
return warning; //可以換成alert等具體操作
}
function onunload_handler(){
var warning="謝謝光臨";
alert(warning); //關閉後執行
}
</script>