beforeunload-false-prevent3.html 428 B

123456789101112131415161718
  1. <html>
  2. <body>
  3. <script type="text/javascript" charset="utf-8">
  4. // Only prevent unload on the first three window closes
  5. var unloadPreventedCount = 0;
  6. window.onbeforeunload = function() {
  7. setTimeout(function() {
  8. require('electron').remote.getCurrentWindow().emit('onbeforeunload');
  9. }, 0);
  10. if (unloadPreventedCount < 3) {
  11. unloadPreventedCount++;
  12. return false;
  13. }
  14. }
  15. </script>
  16. </body>
  17. </html>