关闭时才执行的javasciprt

来源:互联网 发布:文案写得很好的淘宝店 编辑:程序博客网 时间:2024/06/05 05:42
   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>  
0 0
原创粉丝点击