窗口的Java脚本在关闭在IE8 [英] Java Script On Close of window in IE8

查看:127
本文介绍了窗口的Java脚本在关闭在IE8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一些功能时,浏览器会被关闭。

I have implemented some function when the browser will be closed.

window.onbeforeunload = function (evt) {

    evt = (evt)? evt:event;
    clickY = evt.clientY;
    altKey = evt.altKey; 
    keyCode = evt.keyCode; 

if (altKey == true && keyCode == 0){ 
            //Make call to the server to clear the cache                   
    }else if(clickY < 0){
     //Make a call to the server to clear the cache
    }else {
        return;
    }             
};

现在在上面code问题是当过我preSS通过点击地址栏输入或我刷新与刷新按钮的页面我的code给我警报(21112),我不想,因为如果在浏览器关闭呼叫将仅只会触发。
因此,可以有人帮助我实现这一目标。

Now the problem in the above code is when ever i press enter by clicking in the addressbar or i refreshed the page with refresh button my code gives me alert("21112") which i don't want because the call will trigger only and only if the browser is closed. So can somebody help me to achieve this.

推荐答案

window.onbeforeunload 事件之前调用你的页面的 卸载 版。
有没有方法来检查它是否刷新或浏览器窗口关闭的事件。

window.onbeforeunload event is calls before your page is unloaded. There is no method to check if it's refresh or browser window close event.

这触发不同的场景 MSDN

It fires by different scenarios MSDN:


  • 关闭当前窗口。

  • 将进入一个新的地址,或者选择一个喜欢的导航到另一个位置。

  • 单击指向另一个文档的锚点。

  • 调用 anchor.click 方法。

  • 调用文件撰写方法。

  • 调用 document.close 方法。

  • 调用 window.close 方法。

  • 调用 window.navigate 或NavigateAndFind方法。

  • 调用 location.replace 方法。

  • 调用 location.reload 方法。

  • 指定为 location.href 属性的新值。

  • 提交一个表单,通过输入action属性所指定的地址键入=提交控制,或调用 form.submit 方法。

  • 调用 window.open 方法,提供了可能值 _self 为窗口名称。

  • 调用 document.open 方法。

  • 单击后退,前进,刷新,或主页按钮。

  • Close the current window.
  • Navigate to another location by entering a new address or selecting a Favorite.
  • Click an anchor that refers to another document.
  • Invoke the anchor.click method.
  • Invoke the document.write method.
  • Invoke the document.close method.
  • Invoke the window.close method.
  • Invoke the window.navigate or NavigateAndFind method.
  • Invoke the location.replace method.
  • Invoke the location.reload method.
  • Specify a new value for the location.href property.
  • Submit a form to the address specified in the ACTION attribute via the INPUT type=submit control, or invoke the form.submit method.
  • Invoke the window.open method, providing the possible value _self for the window name.
  • Invoke the document.open method.
  • Click the Back, Forward, Refresh, or Home button.

和你不能处理这个问题。

And you can't handle this.

另外请注意, window.onbeforeunload 事件应该告知他离开网页和处理函数用户应收益字符串这将包括在确认弹出值(除火狐4 + 看的错误)。

Also note that window.onbeforeunload event supposed to inform user that he leaves page and handler function should return string value that will be included in confirmation popup (except Firefox 4+ see bug).

您不能强制用户停留在页面上。

You can not force the user to stay on the page.

请注意:您可以用 onbeforeunload 做的唯一一件事就是通知他离开你的页面的用户
(这是因为一些的的网页可以打开另一个页面等...和垃圾邮件的用户,这是安全限制)。

Note: The only thing you can do with onbeforeunload is to notify the user that he is leaving your page (this is because some evil pages can open another pages and so on... and spam users. This is security restriction).

如果你想使AJAX调用卸载窗口之前,你需要使用 onunload的事件。请注意,您的AJAX调用必须我的 SYNCHRONUS 。异步调用将无法工作。

If you want to make AJAX call before window is unloaded you need to use onunload event. Note that your AJAX call must me synchronus. Asynchronous call will not work.

这篇关于窗口的Java脚本在关闭在IE8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆