`

关闭时才执行的javasciprt

阅读更多
   1. <html>  
   2.     <script src="jquery.js"></script>  
   3.     <script   language="javascript">     
   4.   window.onbeforeunload=function()    
   5.   {     
   6.       var   n   =   window.event.screenX   -   window.screenLeft;     
   7.       var   b   =   n   >   document.documentElement.scrollWidth-20;     
   8.       if(b   &&   window.event.clientY   <   0   ||   window.event.altKey)     
   9.       {     
  10.           alert("是关闭而非刷新");     
  11.          sendAjax('http://localhost:8888/testStruts2/test/test.action','');     //这里可以放置你想做的操作代码     
  12.       }     
  13.   }     
  14.   </script>  
  15.     <script>  
  16.     function sendAjax(url,data){  
  17.             $.ajax({  
  18.        type: "POST",  
  19.        url: url,  
  20.        data: data,  
  21.        success: function(msg){  
  22.          alert( "Data Saved: " + msg );  
  23.        }  
  24.         });  
  25.     }  
  26.     </script>  
  27.   
  28.     <input type="button" onclick="sendAjax('http://localhost:8888/testStruts2/test/test.action','');"/>  
  29.   
  30. <html>  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics