Only prevent unload the first time it is attempted

This commit is contained in:
Kevin Sawicki 2016-08-03 12:44:18 -07:00
parent 916920844e
commit cce6be1900
3 changed files with 19 additions and 3 deletions

View file

@ -1,12 +1,17 @@
<html> <html>
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
// Only prevent unload on the first window close
var unloadPrevented = false;
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
require('electron').remote.getCurrentWindow().emit('onbeforeunload'); require('electron').remote.getCurrentWindow().emit('onbeforeunload');
}, 0); }, 0);
if (!unloadPrevented) {
unloadPrevented = true;
return false; return false;
} }
}
</script> </script>
</body> </body>
</html> </html>

View file

@ -1,12 +1,18 @@
<html> <html>
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
// Only prevent unload on the first window close
var unloadPrevented = false;
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
require('electron').remote.getCurrentWindow().emit('onbeforeunload'); require('electron').remote.getCurrentWindow().emit('onbeforeunload');
}, 0); }, 0);
if (!unloadPrevented) {
unloadPrevented = true;
return ''; return '';
} }
}
window.close(); window.close();
</script> </script>
</body> </body>

View file

@ -1,12 +1,17 @@
<html> <html>
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
// Only prevent unload on the first window close
var unloadPrevented = false;
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
require('electron').remote.getCurrentWindow().emit('onbeforeunload'); require('electron').remote.getCurrentWindow().emit('onbeforeunload');
}, 0); }, 0);
if (!unloadPrevented) {
unloadPrevented = true;
return false; return false;
} }
}
window.close(); window.close();
</script> </script>
</body> </body>