As suggested by drumm in the development mailing list, altering the preview page using jquery is one way to keep users from losing the data they just entered when navigating away from the preview page.

There are two possible approaches here, disable links, or ask for confirmation when a link is clicked. Handling confirmation when a user navigates away would require some browser-specific javascript code.

/**
 * Disable links inside of a node preview, to ensure that users don't 
 * accidentally go to a different page a lose their content.
 */
Drupal.behaviors.nodePreviewProtect = function(context) {
  $("div.preview a", context).click(function() {
    // Do not navigate away from the page.
    return false;  
  }).attr("title", Drupal.t("Links are disabled during preview."));
}
/**
 * Make sure that users don't go to a different page and unintentionally 
 * lose their content.
 */
Drupal.behaviors.nodePreviewProtect = function(context) {
  $("div.preview a", context).click(function() {
    if (!confirm(Drupal.t("Are you sure you want to navigate away from this page?"))) {
      // Do not navigate away from the page.
      return false;
    }
  });
}

Attached path implements the second option.

CommentFileSizeAuthor
node_preview_protect.patch1.19 KBfloretan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

subscribing. Looks good visually. I'll give it a go later.

meba’s picture

Works, but still fixes just only one scenario:

> Does anybody know why when previewing a node its title
> appears with a link to "/node"? I have seen some users
> accidentally clicking on this link and loosing their content.

AFAIK, Google Docs are alerting user whenever he clicks any link in the page or a back button. This may be a better, more general approach.

moshe weitzman’s picture

This used to be a big problem in prior releases since the back button did not work as expected and your post was lost. today, we issue proper headers so i have not seen a browser that discards your form fields by regenerating a new page. i don't think an alert is needed anymore. if you do, please proviude steps to reproduce a back button failure.

catch’s picture

I think there's another issue dealing with the node title link in previews, I'd be tempted to make it not a link for that specific case.

Overall, I agree with never use a warning - of course that would also require an undo implementation, which we don't have.

If we're going to have warnings though, it should probably come in along with the modal dialogs patch (and maybe replace delete confirmation pages as well as handling 'are you sure'). Definitely needs to be consistently applied though either way - we can't have a situation where you click one link and get warned, then another link and don't get warned and never know what's going to happen click by click.

catch’s picture

Status: Needs review » Needs work
casey’s picture

geerlingguy’s picture

This module might be relevant to some sites: Node Edit Protection.

Anonymous’s picture

Version: 7.x-dev » 8.x-dev

Moving feature request to 8.x.

Anonymous’s picture