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!

CommentFileSizeAuthor
#4 node-edit-protection.zip469 bytesircdirk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

febbraro’s picture

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.

ramper’s picture

I see, thanks. This is a useful module for those moving from a regular word processing background.

deverman’s picture

Any progress on this module we have users losing their work regularly.

ircdirk’s picture

FileSize
469 bytes

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 ;)

throk’s picture

Status: Active » Needs review

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.");  }
	}
};
mcrittenden’s picture

Sub.

febbraro’s picture

If someone could provide a patch that addresses some of these issues I would gladly apply/commit/release it.

geerlingguy’s picture

Subscribe.

Mohammed J. Razem’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Closing this as outdated as this version will no longer be supported/maintained.