James Kirkby James Kirkby - 1 year ago 202
Javascript Question

Unbind window.onbeforeunload() cancel

i'm binding a function to an event with

window.onbeforeunload = function() {

which is working on unload as planned, but if they cancel the onbeforeunload the function is still attached, is it possible to check if the user cancels onbeforeunload

Answer Source

Actually, I found it was quite easy: I just set

window.onbeforeunload = null;

for each click before it was run, allowing the event handler to be run afterwards.