![]() ![]() |
|||||||||||||||||||||||||||||||||
You should be able to do it via JavaScript. on page load, set formChanged to FALSE, and for all elements, add onChange="formChanged=true". For , onSubmit="formChanged=false"; And as the last bit, for the tag, add: onUnload="if (formChanged && !confirm('Are you sure you wanna lose this precious input?')) return false;". Disclaimer: not tested in real life, but should give you the general idea.
Oops, not-so-unexpectedly it cut the HTML tags in the previous comment. the onSubmit event should be for the FORM tag, ofcourse, and the onUnload event for BODY.
The problem with the above-mentioned JavaScript solution is that you can't reliably prevent the page from unloading (returning false doesn't do it). This is by design, since you can imagine what more shady websites would do with the ability to prevent you from closing the window or navigating elsewhere. So in the example given, the user will see the confirm popup, but the page will unload regardless of what their selection is. Now in IE for Windows, you can use the onbeforeunload event to achieve this, but this doesn't work in any other browsers to my knowledge. I think the original suggestion to have something like this be managed by the browser (not the webpage being visited) makes a lot of sense.
Just a side note. I used to use that phrase from the Cask for keyboard validation (I type about 120 WPM, and type certain phrases to get the "feel" of a new keyboard). At one time, it was my favorite short story :) Was weird seeing it in type again, elsewhere than one of my shell windows. D
Would definitely be cool to have the browser handle this. But in the meantime, the good news is that onbeforeunload is supported in the recent 1.7 release of the Mozilla browser... That takes us a step closer to being able to use that approach (happily, most non-IE browsers already do a fairly reliable job of restoring unsubmitted form content when you click the back button)... Speaking of Mozilla, I'm hoping that the new contenteditable features planned for Safari 2.0 will work alongside the designmode feature supported by Mozilla's Midas. Midas finally brought us a cross-platform way to do WYSIWYG editing in forms. Would be nice if that method also works in Safari rather than having to choose between supporting either Mozilla or Safari, or coming up with a more complex way to support both...
|
|
||||||||||||||||||||||||||||||||