如何知道在 Firefox 中是否点击了刷新按钮或浏览器后退按钮 [英] How to know whether refresh button or browser back button is clicked in Firefox

查看:19
本文介绍了如何知道在 Firefox 中是否点击了刷新按钮或浏览器后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Firefox 中知道是点击了刷新按钮还是点击了浏览器后退按钮...对于这两个事件 onbeforeunload() 方法是一个回调.对于 IE,我是这样处理的:

How to know in Firefox whether refresh button is clicked or browser back button is clicked... for both events onbeforeunload() method is a callback. For IE I am handling like this:

function CallbackFunction(event) {
    if (window.event) {
        if (window.event.clientX < 40 && window.event.clientY < 0) {
            alert("back button is clicked");
        }else{
            alert("refresh button is clicked");
        }
    }else{
        // want some condition here so that I can differentiate between
        // whether refresh button is clicked or back button is clicked.
    }
}

<body onbeforeunload="CallbackFunction();"> 

但在 Firefox 中 event.clientXevent.clientY 始终为 0.还有其他方法可以找到它吗?

But in Firefox event.clientX and event.clientY are always 0. Is there any other way to find it?

推荐答案

用于刷新事件

window.onbeforeunload = function(e) {
  return 'Dialog text here.';
};

https://developer.mozilla.org/en-US/docs/Web/API/window.onbeforeunload?redirectlocale=en-US&redirectslug=DOM%2Fwindow.onbeforeunload

$(window).unload(function() {
      alert('Handler for .unload() called.');
});

这篇关于如何知道在 Firefox 中是否点击了刷新按钮或浏览器后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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