Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/272220-onbeforeunload/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.