0

I would like to know if it is possible to check if a certain page has been refreshed after clicking browser reload button or F5 and create a specific function.

For example:

if(page has been refreshed) {
 code
} else {
 other code
}
Daniel
  • 25
  • 5
  • Possible duplicate of [Check if page reloaded or refresh in js](http://stackoverflow.com/questions/5004978/check-if-page-reloaded-or-refresh-in-js) – tt9 Mar 08 '16 at 22:23
  • 1
    And that duplicate has no definitive answer. Looks like the best you can do is use a session cookie or sessionStorage to see if the page was loaded more than once during the same session, however, that doesn't neccessarely mean the page was refreshed. – adeneo Mar 08 '16 at 22:24
  • However, there is the [`pageshow`](https://developer.mozilla.org/en-US/docs/Web/Events/pageshow) event, which could maybe be useful – adeneo Mar 08 '16 at 22:27

1 Answers1

0

when a page is refreshed, the page and all js variables will be restored to its original state. You might be able to do it if you set a flag in the browser's cookies or localstorage, so when the user refresh the page, you can check if the flag was set.

dannielum
  • 346
  • 1
  • 10