Keep users from unintentionally navigating away from node preview pages.
flobruit - March 26, 2008 - 22:14
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | node system |
| Category: | feature request |
| Priority: | normal |
| Assigned: | flobruit |
| Status: | patch (code needs work) |
Jump to:
Description
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.
| Attachment | Size |
|---|---|
| node_preview_protect.patch | 1.19 KB |

#1
subscribing. Looks good visually. I'll give it a go later.
#2
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.
#3
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.
#4
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.
#5