When a user have changed something in a form, then clicks on any link that will direct him to another page, I'd like to trigger a popup with a "Would you like to Save before leaving?" option.
How can I do this?
Example:
<script type="text/javascript">
var shouldConfirm = false;
window.onbeforeunload = function() {
if(shouldConfirm) {
return "You have made unsaved changes. Would you still like to leave this page?";
}
}
</script>
<input id="FullName" type="text" />
<script type="text/javascript">
document.getElementById('FullName').onchange = function() {
shouldConfirm = true;
}
</script>
There's a full article at 4GuysFromRolla.com.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With