소스 검색

Add document ready when using beforeunload

jmontoyaa 7 년 전
부모
커밋
f520636dbb
1개의 변경된 파일11개의 추가작업 그리고 8개의 파일을 삭제
  1. 11 8
      main/template/default/layout/head.tpl

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

@@ -28,14 +28,17 @@ var connect_lang = '{{ "ChatConnected"|get_lang }}';
 var disconnect_lang = '{{ "ChatDisconnected"|get_lang }}';
 
 var logOutUrl = '{{ _p.web_ajax }}course.ajax.php?a=course_logout';
-// Executes course logout when user close the browser tab/window
-$(window).on('beforeunload', function() {
-    // Logout of course just in case
-    $.ajax({
-        url: logOutUrl,
-        success: function (data) {
-            return 1;
-        }
+
+$(document).ready(function () {
+    // Executes course logout when user close the browser tab/window
+    $(window).on('beforeunload', function () {
+        // Logout of course just in case
+        $.ajax({
+            url: logOutUrl,
+            success: function (data) {
+                return 1;
+            }
+        });
     });
 });