在JS中加入:window.onbeforeunload = function(evt) {
    alert("onbeforeunload");
}发现关闭网页时没有弹出alert,为什么?
我还测试了一下网上的代码,如下,也不行。        window.onbeforeunload = function(evt) {
            if ($("#SmallChanged").val() == "true") {
                evt = evt || window.event;
                if (window.event) {
                    if (evt.clientX > document.documentElement.clientWidth && evt.clientY < 0 || evt.altKey)
                        evt.returnValue = "Do you want to leave this page without saving?";
                }
                else {
                    if (clientH < 222)
                        evt.returnValue = "Do you want to leave this page without saving?";
                }
            }
        }        document.onmousemove = function(e) {
            e = e || window.event;
            if (e != window.event) {
                clientW = e.pageX;
                clientH = e.pageY;
            }
        }

解决方案 »

  1.   

    <script   language=javascript>   window.onbeforeunload   =function(){ 
    if(event.clientX> document.body.clientWidth&&event.clientY <0||event.altKey)   
    {   
            alert( "确定要关闭吗 ");   

    }   
    </script> 
      

  2.   


    <script type="text/javascript">
    var MSG_UNLOAD="您的文章内容还没有进行保存!";
    var UnloadConfirm = {};
    UnloadConfirm.set = function(confirm_msg){
    window.onbeforeunload = function(event){
    event = event || window.event;
    event.returnValue = confirm_msg;
       }
    }
    UnloadConfirm.clear = function(){
    window.onbeforeunload = function(){};
    }
    UnloadConfirm.set(MSG_UNLOAD); 
    </script>
      

  3.   

    今天又试了一遍,onbeforeunload在Firefox下是可以的,但我现在用的是QT下的webkit关联的页面,这个函数就没有用了。
      

  4.   

    window.onbeforeunload = function(){
     if( event.clientX>document.body.clientWidth && event.clientY<0 || event.altKey )    {  
                   
     }else if(event.clientY > document.body.clientHeight || event.altKey)
     {
     }   
    }
      

  5.   

    window.onbeforeunload不能被重载吧