很多時候我們都在困擾,如何捕獲瀏覽器關閉事件,網上雖然有很多方法,但都不理想,后來終於找到了一個很好地實現方法,大家可以試試哦,支持幾乎所有的瀏覽器
<script type="text/javascript"> var READYTOPROCESS = false; window.onbeforeunload = function closeWindow(e) { if (!READYTOPROCESS) { //message to be returned to the popup box. var message = '你確定要關閉嗎?', e = e || window.event; if (e) e.returnValue = message; // IE return message; // Safari } }; </script>