diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js
index 50de5a9b70c41dfec23fb9b850bf426b11dae34c..77378b0602e6c1ca04008775f63023f54a576154 100644
--- a/lib/scripts/edit.js
+++ b/lib/scripts/edit.js
@@ -213,6 +213,7 @@ function deleteDraft() {
 /**
  * Activate "not saved" dialog, add draft deletion to page unload,
  * add handlers to monitor changes
+ * Note: textChanged could be set by e.g. html_edit() as well
  *
  * Sets focus to the editbox as well
  */
@@ -234,19 +235,26 @@ jQuery(function () {
         sel.end   = 0;
         DWsetSelection(sel);
         $edit_text.focus();
+
+        var edit_text_content = $edit_text.val();
     }
 
     var checkfunc = function() {
-        textChanged = true; //global var
+        //global var textChanged
+        if ($edit_text.length > 0) {
+            textChanged = edit_text_content != $edit_text.val();
+        } else {
+            textChanged = true;
+        }
+
         summaryCheck();
     };
 
     $editform.change(checkfunc);
     $editform.keydown(checkfunc);
 
-    var edit_text_content = $edit_text.val();
     window.onbeforeunload = function(){
-        if(window.textChanged && edit_text_content != $edit_text.val()) {
+        if(window.textChanged) {
             return LANG.notsavedyet;
         }
     };