I have used beforeunload event on my page so that when user tries to close my website/tab then I prompt the user that they should not leave the site unless all the forms are filled. But the problem is that my page has a rich form which reloads after every section form fill.
Means page has several forms and each has its own submit button. When user saves one form
the page should reload.
But at reload beforeunload
gets fired and asks user "Do you want to leave the website?". The user did not intend to leave the website, they just reloaded the page.
In short I want to avoid beforeunload on page reload and only call it when user tries to close the tab or browser. Is that possible.
I tried the following code but that did not work:
window.onbeforeunload = function(e) {
var e = e || window.event;
var target = e.target.URL;
if (target == "http://mywebsite.com/customerdetails")
{
return false;
}
};