pradeep
pradeep

Reputation: 1057

get refresh event from page

How to get event of page refresh. i want to detect that user has refreshed page

Upvotes: 2

Views: 7641

Answers (3)

Purefan
Purefan

Reputation: 1506

The event you're looking for is beforeunload, you can stop a page refresh like this:

$(window).bind('beforeunload', function(){ 
    return '';
});

Upvotes: 0

dyve
dyve

Reputation: 6023

On $(document).load()

  • read a var current_page from cookie
  • if it's the same as your current page, you have a refresh
  • write current page to var current_page in cookie

Upvotes: 2

TigerTiger
TigerTiger

Reputation: 10806

not sure how to do it in Jquery

window.onbeforeunload = function (e) {
  var e = e || window.event;

  // For IE and Firefox
  if (e) {
    e.returnValue = 'Any string';
  }

  // For Safari
  return 'Any string';
};

https://developer.mozilla.org/en/DOM/window.onbeforeunload

Upvotes: 2

Related Questions