Function window.onbeforeunload

Asked

Viewed 57 times

0

I have this function in my form But I don’t have one button submit, but I have a button that sends the data, and when clicking on it, it appears this Function message below, how can I put an Exception ? Or something like, this button does the Submit function, but it’s not the type="submit"

  $(function () {
    var init_form = $('#model').serialize(); // Result example: "name=&email=&message=" // Cancel event onbeforeunload when Submit 
   $(':submit').click(function () { window.onbeforeunload = null; }); window.onbeforeunload = function () { var check_form = $('#model').serialize(); if (check_form === init_form) return null; return 'Os dados do formulário não foram salvos, deseja permanecer nesta página?'; };
});
  • in place of the message you want me to fire a Exception that’s it?

  • No, I want this button not to be fired this example, because it appears as if it is going to leave the form, only that in fact it is doing the Submit.

  • I managed to solve, I added this line in Function $('#btn-enviar').click(function () { window.onbeforeunload = null; });

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.