From: Shuanglei Tao Date: Sat, 4 Feb 2017 14:02:44 +0000 (+0800) Subject: Add confirm for window closing X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=82148cd61397d238a195af4a47ac03cfea73a5c9;p=ttyd.git Add confirm for window closing --- 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:
- +