用户关闭浏览器页器,弹出一个提示

function PageUnloader() {
    //當用戶退出時是否需要拋出一個提示
    this.UnloadTips = true;

    var _this = this;

    this.Init = function() {
        //當用戶退出時拋出一個提示
        window.onbeforeunload = function(e) { e = window.event || e; return _this.body_onbeforeunload(e); };    
    };
    
    //Unload事件, 當用戶退出時是否需要拋出一個提示
    this.body_onbeforeunload = function(e) {
        if (this.UnloadTips) {
            return "Your project has not been saved and any changes made will be lost!";
        }
    };
}

var oUnloader = new PageUnloader();
原文地址:https://www.cnblogs.com/yzenet/p/3910024.html