Created
December 2, 2014 15:46
-
-
Save rodrigocnascimento/1338736c0cb8af0c8ef8 to your computer and use it in GitHub Desktop.
Impedir o usuário sair da página, sem gravar os dados
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$( 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