JS离开页面 弹窗

function bindDOMEvents() {
        $(document).keydown(function (e) {
            var key = e.which || e.keyCode;
            if (key == 116) {
                isPopUpComfirm = false;
            }
        });
        // Attach the event click for all links in the page
        $("a").bind("click", function () {
            isPopUpComfirm = false;
        });
        $("form").bind("submit", function () {
            isPopUpComfirm = false;
        });
        // Attach the event click for all inputs in the page
        $("input[type=submit]").bind("click", function () {
            isPopUpComfirm = false;
        });
    }

调用函数

bindDOMEvents();
        $(window).bind('beforeunload', function () {
            var message = 'Make sure change your status to AWAY?';
            if (typeof event == 'undefined') {
                event = window.event;
            }
            if (isPopUpComfirm && event) {
                event.returnValue = message;
                return message;
            }
        });
原文地址:https://www.cnblogs.com/shy-huang/p/7880250.html