Only prevent unload the first time it is attempted
This commit is contained in:
parent
916920844e
commit
cce6be1900
3 changed files with 19 additions and 3 deletions
7
spec/fixtures/api/beforeunload-false.html
vendored
7
spec/fixtures/api/beforeunload-false.html
vendored
|
@ -1,11 +1,16 @@
|
||||||
<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);
|
||||||
return false;
|
if (!unloadPrevented) {
|
||||||
|
unloadPrevented = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,11 +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);
|
||||||
return '';
|
|
||||||
|
if (!unloadPrevented) {
|
||||||
|
unloadPrevented = true;
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.close();
|
window.close();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
<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);
|
||||||
return false;
|
if (!unloadPrevented) {
|
||||||
|
unloadPrevented = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.close();
|
window.close();
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue