From 3ca84dbb4ea4cd813216fe98671135eaa282fcd1 Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Sat, 28 Oct 2017 15:26:50 +0200 Subject: [PATCH] Attempt to stop navigation when there is an edit in progress. This fixes #16 --- assets/script.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assets/script.js b/assets/script.js index d4fc3cd..25e8c66 100644 --- a/assets/script.js +++ b/assets/script.js @@ -103,6 +103,13 @@ function openEditor() { form.reset(); } }); + + window.addEventListener("beforeunload", function (ev) { + if (isEdited(form)) { + ev.preventDefault(); + return ev.returnValue = "Discard changes?"; + } + }); } document