From 5799b0828f46fd07e219935bc436ff935333a324 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Mon, 15 Sep 2014 11:32:25 -0700 Subject: [PATCH] Added exit confirmation --- client/js/shout.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/js/shout.js b/client/js/shout.js index 2fded363..84d61f8f 100644 --- a/client/js/shout.js +++ b/client/js/shout.js @@ -62,14 +62,14 @@ $(function() { }); socket.on("connect_error", function(e) { - location.reload(); + refresh(); }); socket.on("auth", function(data) { var body = $("body"); var login = $("#sign-in"); if (!login.length) { - location.reload(); + refresh(); return; } if (body.hasClass("signed-out")) { @@ -110,6 +110,7 @@ $(function() { channels: channels }) ); + confirmExit(); } $("body").removeClass("signed-out"); @@ -198,6 +199,7 @@ $(function() { .find(".btn") .prop("disabled", false) .end(); + confirmExit(); }); socket.on("nick", function(data) { @@ -558,6 +560,17 @@ $(function() { ); } + function confirmExit() { + window.onbeforeunload = function() { + return "Are you sure you want to navigate away from this page?"; + }; + } + + function refresh() { + window.onbeforeunload = null; + location.reload(); + } + document.addEventListener( "visibilitychange", function() {