Ver código fonte

Fix ajax call not working on firefox see BT#14149

jmontoyaa 7 anos atrás
pai
commit
3e252155f8
1 arquivos alterados com 22 adições e 11 exclusões
  1. 22 11
      main/template/default/layout/head.tpl

+ 22 - 11
main/template/default/layout/head.tpl

@@ -28,19 +28,30 @@ var connect_lang = '{{ "ChatConnected"|get_lang }}';
 var disconnect_lang = '{{ "ChatDisconnected"|get_lang }}';
 var logOutUrl = '{{ _p.web_ajax }}course.ajax.php?a=course_logout&{{ _p.web_cid_query }}';
 
-// Executes course logout when user close the browser tab/window
-$(function() {
-    $(window).on('beforeunload', function () {
-        // Logout of course just in case
-        $.ajax({
-            url: logOutUrl,
-            async: false,
-            success: function (data) {
-                return 1;
-            }
-        });
+function addMainEvent(elm, evType, fn, useCapture) {
+    if (elm.addEventListener) {
+        elm.addEventListener(evType, fn, useCapture);
+        return true;
+    } else if (elm.attachEvent) {
+        elm.attachEvent('on' + evType, fn);
+    } else{
+        elm['on'+evType] = fn;
+    }
+}
+
+function courseLogout() {
+    $.ajax({
+        url: logOutUrl,
+        success: function (data) {
+            return 1;
+        }
     });
+}
+
+$(function() {
+    addMainEvent(window, 'unload', courseLogout ,false);
 });
+
 </script>
 
 {% include template ~ '/layout/header.js.tpl' %}