Trigger onbeforeunload if form is not submitted
问题 I've got a form which is being submitted via PHP with 3 submit actions: Save and Continue Save and Exit Exit without Saving I'd like to trigger an "OnBeforeUnload" alert to display if the user DOES NOT click on any of the form actions to advise them that they're leaving the page, and their changes may not be saved. I've tried the following code but it seems as though the unbeforeunload is being triggered before my click event. Any suggestions on how best to achieve this? $buttonpressed =