-
-
Save ramonjoaquim/39274b4bebd4e3cdc5d64ef1f2f72757 to your computer and use it in GitHub Desktop.
JavaScript exit page confirmer object
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
Um objeto JavaScript para confirmar se o usuário quer sair da página | |
http://prodis.blog.br/2010/11/29/um-objeto-javascript-para-confirmar-se-o-usuario-quer-sair-da-pagina/ |
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 ExitPageConfirmer(message) { | |
this.message = message; | |
this.needToConfirm = false; | |
var myself = this; | |
window.onbeforeunload = function() { | |
if (myself.needToConfirm) { | |
return myself.message; | |
} | |
} | |
} |
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
<html> | |
<head> | |
<script src="scripts/Prodis.ExitPageConfirmer.js"></script> | |
<script> | |
var exitPage = new ExitPageConfirmer("My confirmation message."); | |
</script> | |
</head> | |
<body> | |
<form onsubmit="exitPage.needToConfirm = false;"> | |
<p><input type="text" onchange="exitPage.needToConfirm = true;" /></p> | |
<p><input type="submit" /></p> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment