The users sometimes close the tab or browser before hitting the "Save and view" button. Is there way to trigger an alert message when this happens?
Thanks!
It worked flawlessly. Thank you!
Is there any way to disable the alert message when users click on "Save and view" to save the data?
One way is suggested in the linked example above where it shows how to use jquery to handle links. You just need to set the click event of the 'Save and view' button to run
function{window.onbeforeunload =null;}
If I understannd it correctly, this solution is the same as the other below it and both approaches would require hacking the /mod/data/edit.php file, with which I am definitely uncomfortable. Could you please give further instructions? Thanks!
For those who are interested, it turned out to be very easy.
1. Add the following javascript code in the Add template as suggested by the link provided by Itamar.
<script type="text/javascript">
var hook = true;
window.Xonbeforeunload= function() {
if (hook) {
return "Did you save your stuff?"
}
}
function unhook() {
hook=false;
}
</script>
2. Add the following code in line 316 and 321 of the edit.php file under moodle\mod\data\.
XonClick="unhook()"
An alternate way which does not involve hacking the php (and thereby avoids upgrade problems) is to use javascript for setting the onclick of the save button of the edit form to 'window.onbeforeunload = null'. That's the approach suggested in the afformentioned link.