From 345da520faf1a242c6702844afd5ea6e105a5579 2013-06-28 22:40:40 From: MinRK Date: 2013-06-28 22:40:40 Subject: [PATCH] restore "unsaved changes" warning on unload Autosave is triggered at this event, but it seems to fail sometimes (perhaps when it's too slow?). closes #3475 --- diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 05eab03..812b9c0 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -345,9 +345,13 @@ var IPython = (function (IPython) { if (kill_kernel) { that.kernel.kill(); } - // if we are autosaving, trigger an autosave on nav-away - if (that.dirty && that.autosave_interval && ! that.read_only) { - that.save_notebook(); + // if we are autosaving, trigger an autosave on nav-away. + // still warn, because if we don't the autosave may fail. + if (that.dirty && ! that.read_only) { + if ( that.autosave_interval ) { + setTimeout(function() { that.save_notebook(); }, 0); + } + return "Unsaved changes will be lost."; }; // Null is the *only* return value that will make the browser not // pop up the "don't leave" dialog.