Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know whether refresh button or browser back button is clicked in Firefox [duplicate]

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();">  

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

like image 355
Coding Avatar asked Aug 27 '13 05:08

Coding


People also ask

What happened to the refresh button on Firefox?

If you press the Firefox menu button and select Customize, you can drag the reload button back to the toolbar. See Customize Firefox controls, buttons and toolbars for more information. Hope this helps. If you press the Firefox menu button and select '''Customize''', you can drag the reload button back to the toolbar.

How do you pop up an alert box when the browsers refresh button is clicked?

You can do it like this: window. onbeforeunload = function() { return "Data will be lost if you leave the page, are you sure?"; };


1 Answers

Use for on refresh event

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

And

$(window).unload(function() {       alert('Handler for .unload() called.'); }); 
like image 160
Er.KT Avatar answered Sep 22 '22 22:09

Er.KT