Hello,

How to force window.onbeforeunload to act only on pertular action or url?
I have a form which has data. if it navigates to another page then
window.onbeforeunload= function() { return "please save data"; };
is working.
But after submission of that page, it navigates to another page on that cation also it is asking me for saving data.
which I dont want.
I want it just for that page url.
Is it possible?
how?

Recommended Answers

All 3 Replies

Try something like this...

if ( window.location.toString().indexOf("myPage.html") > -1 ) {
    window.onbeforeunload...
}

How about something on the submit button
onclick='window.onbeforeunload = null;'
or on

form.submit.

Hello,
Thanks AleMonteiro and almostbob!!
@almostbob: your solution worked for me!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.