You need to sign in to do that
Don't have an account?
MattMet86
Page Leave Alert using the Apex Confirm prompt
Can someone help me code a page leave alert for VF?
I found this code for commandbuttons:
which generates a prompt on the page which is exactly what I want except I need this to occur on page leave instead of on a button click.
My goal is to prevent a user from leaving the page without saving.
I have found the code below online but I am not sure how to swap out the function(e) for the action above.
I want to use the Salesforce alert as the browser will always display my text instead of the hit or miss results I get from this code in different browsers.
Thanks,
I found this code for commandbuttons:
onclick="if(!confirm('Did you do everything?')){return};"
which generates a prompt on the page which is exactly what I want except I need this to occur on page leave instead of on a button click.
My goal is to prevent a user from leaving the page without saving.
I have found the code below online but I am not sure how to swap out the function(e) for the action above.
I want to use the Salesforce alert as the browser will always display my text instead of the hit or miss results I get from this code in different browsers.
<script> var LeaveAllowed = false; var evt = window.attachEvent || window.addEventListener; var checkEvt = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; evt(checkEvt, function(e) { if (!LeaveAllowed) { var msg = 'There may be unsaved changes.'; (e || window.event).returnValue = msg; return msg; } }); function allowLeave() { LeaveAllowed = true; } </script>
Thanks,
I'm not able to test it right now, but that should work or something very similar
Ideas?