0

I have created a form and using the window "onbeforeunload" feature, I've decided to add a confirmation box so that every time the user tries closing the window or reloading the page he gets an alert message.

The problem is that the message is something along the lines of "changes may not be saved" and that same confirmation error pops up when i'm submitting the form!

Is there a way i can get these confirmation pop ups everytime other than when submitting the form?

I've seen some stack exchange questions wherein the OP has asked for an alert when reloading but not closing tab or vice versa. Even in those questions the answer seems to be along the lines of "..It isn't possible..". Have a look at this question, for instance.

So, I have a feeling it might not be possible here too, but is there any other way? For example, i could make the submit button as a normal button and then add some features manually?

I have knowledge of JavaScript/HTML/CSS and nothing more. Perhaps I could learn another language which would make it plausible? Or maybe there is an intrinsic feature I still don't know about?

It would be preferable if I could somehow achieve it without using another language but I'm fine if that is the only option.

1 Answers1

0

You can add a onclick="dontShowAnythingAndSubmit()" to your submit button. Then move the submit button outside the form.

Define your function to override the onbeforeunload.

function dontShowAnythingAndSubmit() {
    window.onbeforeunload = null;
    document.getElementById("yourForm").submit(); 
}

Or did I not completely understand your question?

Kloker
  • 499
  • 4
  • 14