From 82148cd61397d238a195af4a47ac03cfea73a5c9 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sat, 4 Feb 2017 22:02:44 +0800 Subject: [PATCH] Add confirm for window closing --- html/js/app.js | 11 +++++++++-- src/index.html | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/html/js/app.js b/html/js/app.js index da8ddad..ad1687d 100644 --- a/html/js/app.js +++ b/html/js/app.js @@ -9,6 +9,11 @@ var openWs = function() { var ws = new WebSocket(url, protocols); + var unloadCallback = function(event) { + var message = 'Close terminal? this will also terminate the command.'; + (event || window.event).returnValue = message; + return message; + }; ws.onopen = function(event) { console.log("Websocket connection opened"); @@ -38,9 +43,10 @@ }); term.on('open', function() { - window.onresize = function(event) { + window.addEventListener('resize', function(event) { term.fit(); - }; + }); + window.addEventListener('beforeunload', unloadCallback); term.fit(); term.focus(); }); @@ -86,6 +92,7 @@ term.showOverlay("Connection Closed", null); } } + window.removeEventListener('beforeunload', unloadCallback); clearInterval(pingTimer); if (autoReconnect > 0) { setTimeout(openWs, autoReconnect * 1000); diff --git a/src/index.html b/src/index.html index a0c65aa..0bb92bd 100644 --- a/src/index.html +++ b/src/index.html @@ -16,6 +16,6 @@ break;case 33:t.shiftKey?e.scrollDisp=-(this.rows-1):e.key="[5~";break;case 34:
- + -- 2.43.4