0

I tried to do this:

location.reload = function() { return false }

But it seems to be denied as it still reloads the page.

EDIT

I do not want to do any harm for a user and lock it into the page. The case where I need it is - integration testing on an existing code base which has location.reload() and location.href = '...' all over the place.

lukas.pukenis
  • 13,057
  • 12
  • 47
  • 81

1 Answers1

0

You can use onbeforeunload

window.onbeforeunload = function () {

  return confirm("Are you sure you want to leave?");

};

However this is not supported in firefox and opera for that this may be help you

window.onbeforeunload and window.onunload is not working in Firefox , Safari , Opera?

Community
  • 1
  • 1
commit
  • 4,777
  • 15
  • 43
  • 70