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

查看:119
本文介绍了如何知道刷新按钮或浏览器的后退按钮是否被点击在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.clientX event.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.';
};

<一个href=\"https://developer.mozilla.org/en-US/docs/Web/API/window.onbeforeunload?redirectlocale=en-US&redirectslug=DOM%2Fwindow.onbeforeunload\">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天全站免登陆