Skip to content

Instantly share code, notes, and snippets.

@rodrigocnascimento
Created December 2, 2014 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigocnascimento/1338736c0cb8af0c8ef8 to your computer and use it in GitHub Desktop.
Save rodrigocnascimento/1338736c0cb8af0c8ef8 to your computer and use it in GitHub Desktop.
Impedir o usuário sair da página, sem gravar os dados
$( function(){
var init_form = $('#id_form').serialize();
// Result example: "name=&email=&message="
// Cancel event onbeforeunload when Submit form
$(':submit').click(function() {
window.onbeforeunload = null;
});
window.onbeforeunload = function(){
var check_form = $('#id_form').serialize();
if( check_form === init_form )
return null;
return 'Os dados do formulário não foram salvos, deseja permanecer nesta página?';
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment