Prevent page refresh?

Maybe you can do it with custom code on some browsers.
But you should not.
It’s bad behavior and the user should always have control over the browser.
You can prompt alert before refreshing though:
.
Why do you need that?