Explorar o código

improving solution for firefox location issue listening to onbeforeunload

Falko Schindler %!s(int64=2) %!d(string=hai) anos
pai
achega
aa2b30cfc6

+ 1 - 1
nicegui/static/templates/js/event_handler.js

@@ -133,7 +133,7 @@ function send_to_server(e, event_type, debug_flag) {
     }
     if (use_websockets) {
         if (web_socket_closed) {
-            setTimeout(function(){ window.location.reload(); }, 100);
+            window.location.reload();
             return;
         }
         if (websocket_ready) {

+ 5 - 2
nicegui/static/templates/main.html

@@ -86,14 +86,17 @@
 
         socket.addEventListener('error', function (event) {
             console.log('Websocket closed');
-            setTimeout(function(){ window.location.reload(); }, 100);
+            window.location.reload();
         });
 
+        var unloading = False;
+        window.onbeforeunload = function () { unloading = True; }
+
         var web_socket_closed = false;
         socket.addEventListener('close', function (event) {
             console.log('Websocket closed');
             web_socket_closed = true;
-            setTimeout(function(){ window.location.reload(); }, 100);
+            if (!unloading) window.location.reload();
         });
 
         socket.addEventListener('message', function (event) {