页面关闭时,提示是否关闭,js 或 jquery 实现
原创 everyBody 发表于:2018-04-04 10:31:35
  阅读 :83   收藏   编辑

注意:打开chrome浏览器后,随便敲几个键盘,即可

code:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="http://code.jquery.com/jquery-1.4.1.min.js"></script>

    </head>
    <body>
    </body>
     <script type="text/javascript">

        //jquery写法
        $(window).bind('beforeunload', function() {
            return '您输入的内容尚未保存,确定离开此页面吗?';
        });
        $(window).unbind('beforeunload');

        //或使用原生js
        window.onbeforeunload = function(event) {
            return confirm("确定退出吗");
        }
    </script>
</html>