日期:2014-05-16  浏览次数:20421 次

JQuery获取浏览器关闭的事件函数
需求:我希望在用户关闭浏览器的时候 执行一些操作
项目是 B/S 结构项目   通俗点说就是:用户在客户端把浏览器给关了  我的应用程序需要捕获 客户端 这个 “关闭浏览器的动作”  执行逻辑操作!
我在JQuery的API上找了一个函数: 
事件语法:
.unload( handler(eventObject) )
 
handler(eventObject)A function to execute when the event is triggered.
适用场景:
The unload event is sent to the window element when the user navigates away from the page. This could mean one of many things. 
The user could have clicked on a link to leave the page, or typed in a new URL in the address bar. (用户点击一个离开页面的链接或者在地址栏重新键入一个新的地址)
The forward and back buttons will trigger the event.(点击前进 后退 按钮)
Closing the browser window will cause the event to be triggered. (关闭浏览器)
Even a page reload will first create an unload event.或者重新载入页面

  问问 有木有 只有监听浏览器关闭的事件?
------解决方案--------------------
适用ie浏览器方法,有

但是不知道适不适用其他的浏览器。
------解决方案--------------------
IE可以使用下面的代码

    window.onbeforeunload = function (e) {
        e = e 
------解决方案--------------------
 window.event;
        var y = e.clientY
        if (y <= 0
        
------解决方案--------------------
 y >= Math.max(document.body.clientHeight, document.documentElement.clientHeight)
        )
            e.returnValue = "确认关闭浏览器窗口?!!";
    }

参考这个:javascript判断浏览器是否关闭
------解决方案--------------------
引用:
IE可以使用下面的代码

JavaScript code?12345678    window.onbeforeunload = function (e) {        e = e 
------解决方案--------------------
 window.event;        var y = e.clientY        if (y <= 0        
------解决方案--------------------
 y >= Math.max(document……

试了,没看到效果?