window.onbeforeunload = function() {
return 'are you sure you want to leave?';
}
<a href="javascript:void(0)" onclick="someFunction()">button</a>
Is there a way to prevent Internet Explorer from triggering the onbeforeunload callback whenever someone clicks on an anchor? I believe that IE thinks that all anchors are used to leave pages. However, my code uses the anchor as a button. If I change my code to…
<a href="#" onclick="someFunction()">button</a>
… onbeforeunload is not called anymore, but it’s bad for my user interface - the page suddenly jumps to the top. I think if I change all my anchor buttons to actual <button>s then it would solve the problem, but I really do like how anchors have the default CSS cursor styling…