1

I can't check browser location reloaded in js ?

I tried that but it doesn't work because performence type not work anymore in any browser.

I tried that code. But it doesn't work.

if (window.performance) {
  console.info("window.performance works fine on this browser");
}
if (performance.navigation.type == performance.navigation.TYPE_RELOAD) {
  console.info("This page is reloaded");
} else {
  console.info("This page is not reloaded");
}
epascarello
  • 204,599
  • 20
  • 195
  • 236
Hakimov-dev
  • 234
  • 2
  • 10

1 Answers1

0

I recommended to you use this:

window.onbeforeunload = function(event) {
  var message = 'Are you sure you want to reload this page?';

  // Check if the event is a location reload
  if (event.currentTarget.performance && event.currentTarget.performance.navigation.type === 1) {
    // The current page is being reloaded
    // Perform your desired actions here
    console.log('Page is being reloaded');
  }

  // You can also display a confirmation message
  return message;
};
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Was this copied from somewhere? The (original) lead was completely out of whack with the text in the code comments. [ChatGPT](https://meta.stackoverflow.com/questions/421831/temporary-policy-chatgpt-is-banned) plagiarism? Ordinary plagiarism? – Peter Mortensen Jul 03 '23 at 13:05