问题描述
如何在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!