Reputation: 6398
I want to prevent the page loading when "Editing" on m page occures.
so i got this code
window.onbeforeunload = function() {
return "Are you sure you want to navigate away?";
}
Now i need to unbind this from the page.
is there any methods available ?
Thank you.
Upvotes: 1
Views: 5789
Reputation: 47
You should use some flag to check if page is editing values or just navigating to other page
you can follow this thread too Javascript, controlling an onbeforeunload tag
Upvotes: 1
Reputation: 337714
To unbind the event, set it to null:
window.onbeforeunload = null;
It may however be better for program flow to put a condition inside your onbeforeunload
handler, so that you have a single function running on page unload:
window.onbeforeunload = function() {
if (myVar == "Editing")
return "Are you sure you want to navigate away?";
}
Upvotes: 1