Only prevent unload the first time it is attempted
authorKevin Sawicki <kevinsawicki@gmail.com>
Wed, 3 Aug 2016 19:44:18 +0000 (12:44 -0700)
committerKevin Sawicki <kevinsawicki@gmail.com>
Wed, 3 Aug 2016 23:23:39 +0000 (16:23 -0700)
spec/fixtures/api/beforeunload-false.html
spec/fixtures/api/close-beforeunload-empty-string.html
spec/fixtures/api/close-beforeunload-false.html

index e34a194..4ba1867 100644 (file)
@@ -1,11 +1,16 @@
 <html>
 <body>
 <script type="text/javascript" charset="utf-8">
+  // Only prevent unload on the first window close
+  var unloadPrevented = false;
   window.onbeforeunload = function() {
     setTimeout(function() {
       require('electron').remote.getCurrentWindow().emit('onbeforeunload');
     }, 0);
-    return false;
+    if (!unloadPrevented) {
+      unloadPrevented = true;
+      return false;
+    }
   }
 </script>
 </body>
index 2efaac3..13564fb 100644 (file)
@@ -1,11 +1,17 @@
 <html>
 <body>
 <script type="text/javascript" charset="utf-8">
+  // Only prevent unload on the first window close
+  var unloadPrevented = false;
   window.onbeforeunload = function() {
     setTimeout(function() {
       require('electron').remote.getCurrentWindow().emit('onbeforeunload');
     }, 0);
-    return '';
+
+    if (!unloadPrevented) {
+      unloadPrevented = true;
+      return '';
+    }
   }
   window.close();
 </script>
index 0359078..482b875 100644 (file)
@@ -1,11 +1,16 @@
 <html>
 <body>
 <script type="text/javascript" charset="utf-8">
+  // Only prevent unload on the first window close
+  var unloadPrevented = false;
   window.onbeforeunload = function() {
     setTimeout(function() {
       require('electron').remote.getCurrentWindow().emit('onbeforeunload');
     }, 0);
-    return false;
+    if (!unloadPrevented) {
+      unloadPrevented = true;
+      return false;
+    }
   }
   window.close();
 </script>