[JS] 補捉使用者關閉IE視窗

  • 4810
  • 0
  • 2009-08-04

摘要:補捉使用者關閉IE視窗

補捉使用者關閉IE視窗的程式碼

    <script type="text/javascript" language="javascript">
    
    window.onunload = CloseWindows;  
    function CloseWindows()  
    {  
        //按下X關閉  
        if (event.clientY < 0)  
        {  
                 try  
                 {    
                     alert("hi");
                     var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
                     //使用者自行關閉視窗時
                     xmlhttp.open("POST","CloseWindow.aspx", false);  
                     xmlhttp.send();  
                     return true;  
                }
  
                catch(e)  
                {  
                     alert('close windows error message:' + e.message);  
                }
  
        }
  
    }
  
    
    </script>

 有效運用可以做不少事喔!

  -----------------------
Share is power

 

 

-----------------------
Share is Power