Portal Home > Knowledgebase > Articles Database > Confirmation before user leaves page, UNLESS certain button clicked
Confirmation before user leaves page, UNLESS certain button clicked
Posted by gpl24, 11-13-2011, 11:36 PM |
I would like to throw an alert at the user if they click off a particular page, UNLESS the "Submit" button is clicked.
Similar to what facebook does in private messages -- they will give you a confirmation alert if your message hasn't been sent. If it has sent, you don't get any alert.
The code I've tried always shows, even if the button is clicked. What do I have to do to cancel the alert event if the button is clicked?
Code in header:
The button I would like to override the alert:
the onClick() event just blocks multiple clicks (it doesn't show any alert unless the user clicks the submit button multiple times), it's unrelated to the onbeforeunload event.
|
Posted by MrKenTX, 11-17-2011, 01:57 AM |
I am working on a similar project now. I maintain a variable to control whether the form has been edited or not and use the window.onbeforeunload event. Word of warning, this is only a demo and has not been fully tested with all browsers for compatibility.
|
Posted by H0$T, 11-18-2011, 01:43 PM |
I did same thing for a client of mine but I used jquery instead of pure JavaScript. The thing works well now. Maybe using jquery to listen event and adding exception to handle what you want is good way to do it.
|
Add to Favourites Print this Article
Also Read
sync hosting (Views: 688)