NotSavedWarning-Talk
Alternative solution
I've implemented pretty much the exact same functionality [alert box if moving away from a modified edit form] with the following JavaScript. It checks for the form element type as I was getting false positives from using <button> instead of <input type="submit">. I also don't bother with the check for page preview if the contents are not modified, as navigating back will in that case show the previewed contents. --Eemeli Aro March 12, 2009, at 05:06 AM
function addEvent( obj, evt, fn ) { if (obj.addEventListener) obj.addEventListener( evt, fn, false ); else if (obj.attachEvent) obj.attachEvent( 'on'+evt, fn ); } function removeEvent( obj, evt, fn ) { if (obj.removeEventListener) obj.removeEventListener( evt, fn, false ); else if (obj.detachEvent) obj.detachEvent( 'on'+evt, fn ); } var ef; function verifyExitOnEdit(e) { if (!ef) return; var evt = e || window.event; var msg = "All changes will be lost."; for ( var i in ef.elements ) { if ( ( ef.elements[i].type in { 'text':'', 'textarea':'' } ) && ( ef.elements[i].value != ef.elements[i].defaultValue ) ) { if (evt) evt.returnValue = msg; return msg; } } } addEvent( window, 'load', function() { var et = document.getElementById('text'); if (et) { ef = et.form; addEvent( window, 'beforeunload', verifyExitOnEdit ); addEvent( ef, 'submit', function() { removeEvent( window, 'beforeunload', verifyExitOnEdit ); } ); } } );
ExcelPaste compatibility
Using the convert tabs to table functionality (from the GUI edit button ) the confirm message is shown when it isn't really required
The Notsaved recipe has indeed troubles with ExcelPaste and I am not sure how to fix them. The GUI button actually submits the form to PmWiki (we could disable this warning) but the changes aren't saved. Worse, when an edit form reappears, Notsaved has no way of knowing that the form comes from ExcelPaste and not from the real saved page content, so if the author moves away without changing the form, no warnings will appear. --Petko August 21, 2009, at 06:17 PM
International characters
How can german umlauts ("ÄÖÜäöüß") be used in message?
Make sure you save your config.php file in the same encoding as the wiki: UTF-8 if the wiki has UTF-8 enabled, or ANSI/Latin-1 if the wiki is in ISO8859-1 (default installation). --Petko August 21, 2009, at 06:17 PM
Minor, but should it not be "NotSavedWarning" ? simon August 18, 2012, at 03:15 AM
$RecipeInfo['Notsaved']['Version'] = '20110829';
needs to be changed to $RecipeInfo['NotSaved']['Version'] = '20110829';
to work with recipe check, ta
Thanks for integrating "remember position", Petko!
A minor issue, already present in earlier versions: After a "Preview", but without changing content, the warning appears if I try to leave the page. Not worth to fix since people should not "Preview" if they didn't change anything OliverBetz 2015-08-27
This is a known feature. After the "Preview" page appears, for the JavaScript it is a new page, and the recipe cannot know if the content was modified or not before pressing Preview. I prefer to warn the user even if it is not needed, rather than fail to warn the user when it is needed. --Petko August 27, 2015, at 01:21 PM
Bug (and fix) with (at least) Chrome
When Cancel is pressed after a prompt for the Summary or Author fields, the POST submits. The best fix appears to be calling preventDefault() on the event before returning false in the NsSubmit event handler:
- function NsSubmit() { + function NsSubmit(evt) { ... - else {NsForm.author.focus(); return false;} + else {NsForm.author.focus(); evt.preventDefault(); return false;} ... - else {NsForm.csum.focus(); return false;} + else {NsForm.csum.focus(); evt.preventDefault(); return false;}
Damien Palmer July 11, 2017, at 08:56 PM
Excellent catch, thanks! --Petko July 11, 2017, at 11:31 PM
Talk page for the NotSavedWarning recipe (users).