在jquery / javascript中检测浏览器关闭以便跨浏览器

时间:2013-02-18 10:42:27

标签: javascript jquery asp.net

window.onbeforeunload / window.onunload无法在chrome中工作以检测浏览器关闭事件。需要一些帮助!

1 个答案:

答案 0 :(得分:2)

检查一下 http://help.dottoro.com/ljhtbtum.php

示例 http://help.dottoro.com/external/examples/ljhtbtum/onbeforeunload_1.htm

<head>
    <script type="text/javascript">
        function OnBeforeUnLoad () {
            return "All data that you have entered will be lost!";
        }
    </script>
</head>
<body onbeforeunload="return OnBeforeUnLoad ()">
    <b>Close this window or press F5 to reload the page.</b>
    <br /><br />
    <form>
        User name: <input type="text" name="username" />
        <br />
        City: <input type="text" name="city" />
    </form>
</body>