读书人

JS 判断窗口是不是关闭

发布时间: 2012-10-29 10:03:53 作者: rapoo

JS 判断窗口是否关闭

关键字:       window.close事件     javascript捕获窗口关闭事件有两种方法 onbeforeunload()      ,onUnload() 用法有两种:1.    function      window.onbeforeunload()      {      alert("关闭窗口")}           function      window.onunload()      {      alert("关闭窗口")}2.      在body 标签里加入onUnload事件         <body onUnload="myClose()">         然后在javascript里定义myClose()方法  区别:          onUnload方法是在关闭窗口之后执行          onbeforeUnload方法是在关闭窗口之前执行 说明:          两个方法在 页面关闭、刷新、转向新页面 时都触发。注:只在关闭窗口时触发,而页面刷新的时不触发。<script       language=javascript>         function       window.onbeforeunload()         {         if       (event.clientX>document.body.clientWidth       &&       event.clientY<0||event.altKey)            {                window.event.returnValue="确定要退出本页吗?";               }         }</script>    
?

读书人网 >JavaScript

热点推荐