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


This question already has an answer here:


Use for on refresh event

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


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

Use 'event.currentTarget.performance.navigation.type' to determine the type of navigation. This is working in IE, FF and Chrome.

function CallbackFunction(event) {
    if(window.event) {
        if (window.event.clientX < 40 && window.event.clientY < 0) {
            alert("back button is clicked");
            alert("refresh button is clicked");
        if (event.currentTarget.performance.navigation.type == 2) {
            alert("back button is clicked");
        if (event.currentTarget.performance.navigation.type == 1) {
            alert("refresh button is clicked");

For Back Button in jquery //

 jQuery(window).bind("unload", function() { //

and in html5 there is an event The event is called 'popstate'

window.onpopstate = function(event) {
alert("location: " + document.location + ", state: " + JSON.stringify(event.state));

and for refresh please check Check if page gets reloaded or refreshed in Javascript

In Mozilla Client-x and client-y is inside document area

var keyCode = evt.keyCode;
if (keyCode==8)
alert('you pressed backspace');

alert('you pressed f5 to reload page')

Need Your Help

Inspecting javascript on in Google Chrome

javascript google-chrome jsfiddle google-chrome-devtools

Is it possible to set breakpoints using the google chrome inspector on javascript code entered into