rklockner Posted December 20, 2012 Share Posted December 20, 2012 I have a site that contains an internal messaging system. I've had users complain that they lost a message they were typing because the navigated away from the page. When this occurs, I'd like to display a custom popup box that I have built (with options, Save, Delete, and Cancel). If save is clicked, it would save a draft then continue to the link the user clicked. If Delete is clicked, it would not save a draft, then continue to the link. If Cancel is clicked, it would go back to the message and allow the user to continue typing. I've played with this option, but it displays the default alert option box. Not desireable. window.onbeforeunload = saveCurrentMessage; My only other thought is to do something like $('a').click(function(){ //cancel the href/onclick from the tag and store in a variable. //display my box. //depending on what the user clicks, Save/Delete would take that action then fire the href and/or onclick, Cancel would just cancel }); NOTE: I don't want to change the a tags on any other page than this, so modifying every link is not an option. Has anyone done this or have any thoughts in this direction? Thanks, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/272220-onbeforeunload/ Share on other sites More sharing options...
Jessica Posted December 21, 2012 Share Posted December 21, 2012 Use jquery, it'll be easy to do all of that. Quote Link to comment https://forums.phpfreaks.com/topic/272220-onbeforeunload/#findComment-1400700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.