Conditional onbeforeunload event in a page

javascript, jquery

Solution

You could just remove `window.onbeforeunload` in the click handler.

Problem

``` window.onbeforeunload = function(evt) { var message = 'Are you sure you want to leave the page. All data will be lost!'; if (typeof evt === 'undefined') { evt = window.event; } if (evt && !($("#a_exit").click)) { evt.returnValue = message; } return message; }; ``` I want user to leave the page clicking to the link (has `id ="a_exit"`) only. In other circumstances such as refreshing the page, clicking another link, user will be prompted that if he/she wants to leave the page. I have tried to use the code above. It still asks me if I want to go away when I click the exit link.

Original source