IE页面关闭前弹出窗口 是否保存信息

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    
    <script type="text/javascript">
        function getEvent() //同时兼容ie和ff的写法, 这个方法是网上copy的 
        {
            if (document.all) return window.event;
            func = getEvent.caller;
            while (func != null) {
                var arg0 = func.arguments[0];
                if (arg0) {
                    if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
                        return arg0;
                    }
                }
                func = func.caller;
            }
            return null;
        }
        function ConfirmClose() {
            if (window.event) {
                var IsClose = window.confirm("当前编辑的文章内容是否保存?");
                if (!IsClose) {
                    window.onbeforeunload = null;
                } else {
                    window.onbeforeunload = null;
                    window.returnValue = { "Content": Ext.getCmp("Content").getValue() };
                    window.close();
                }
                
            }
            else
                getEvent().preventDefault();  //for firefox
        }
        function on_page_loaded()   //自己定义的body的onload事件 
        {
            try {
                if (!window.onbeforeunload)    //为了不覆盖原来的onbeforeunload方法,先判断
                    window.onbeforeunload = ConfirmClose;   //todo 增加了窗口关闭前的提示
            } catch (e) { 
            }
        }
    </script>
</head>
<body onload="on_page_loaded();">
    <div id="EditForm">
    </div>
</body>
</html>

你可能感兴趣的:(function,object,IE,null,firefox)