Posted by ramper on December 5, 2008 at 9:35pm
| Project: | Node Edit Protection |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
Hi, this is a great little module - anything that will make someone switching from a regular 'word processing' background feel more at ease is great. Of course, a web browser is not the same as a word processor...
Knowing nothing about how browsers work, I was wondering - is it possible to monitor clicking on the browser 'Back' or 'Forward' button as well? This module gives a warning when you click on a link - but a lot of times people simply navigate away using the 'Back' button. Thanks for this great module!
Comments
#1
I am listening to the window unload event. It gets fired when using the back button, but it appears to get called too late in the process to actually prevent the back action from happening. So, it seems they get a warning, but it does not stop them. I'll have to investigate a bit further, but the back button is obviously a big one and difficult one to get around.
#2
I see, thanks. This is a useful module for those moving from a regular word processing background.
#3
Any progress on this module we have users losing their work regularly.
#4
Yes its possible i made my own version of node-edit-protection.js It does work for back buttons and jquery using window.onbeforeunload. Please check it out. Its simple and it works ;)
#5
I tested ircdirk's code and it does in fact work. BUT, it does not work at all in Internet Explorer 8 (I haven't tested other versions). It works fine in Firefox and Chrome.
It would be nice if both versions could be combined so that they work in both browsers. I'm not very good at Javascript so I'm not really the guy to dive into this.
I'm re-posting ircdirk's code here so that it can be seen w/o downloading and unzipping it.
Drupal.node_edit_protection = {};
Drupal.behaviors.nodeEditProtection = function(context) {
if ( $("#node-form").length > 0 ) {
window.onbeforeunload = confirmExit;
var global_formNavigate = true;
$("#node-form").change(function(){
global_formNavigate = false;
});
$(".node-form input[@type='submit']").click(function(){
global_formNavigate = true;
});
}
function confirmExit() {
if (global_formNavigate == true) { event.cancelBubble = true; } else { return Drupal.t("You are about to leave a form that may contain changes that will not be saved."); }
}
};
#6
Sub.
#7
If someone could provide a patch that addresses some of these issues I would gladly apply/commit/release it.
#8
Subscribe.