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;
            }
        });
posted @ 2017-11-22 17:18  肖恩部落  阅读(638)  评论(0编辑  收藏  举报