XMLHttpRequest 跟踪问题(仅适用于 Firefox 和 Safari)

XMLHttpRequest tracking issue (only for Firefox and Safari)

我正在使用一个系统来跟踪用户 activity。它在 Google Chrome 上就像一个魅力,但在 Firefox 和 Safari 上不起作用(我猜是由 window.close 引起的)因为我的数据库中没有写 'end_start'页面结果仍然打开:

jsHandler.js

function start(pageName) {
    var xmlhttp3;
    if (window.XMLHttpRequest) {
        xmlhttp3 = new XMLHttpRequest();
    } else {
        xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp3.onreadystatechange=function() {
    if (xmlhttp3.readyState==4 && xmlhttp3.status==200) {

    }
}

xmlhttp3.open("GET","includes/trackStart.php?pageName="+pageName,true);
    xmlhttp3.send();
}


function end() {
    var xmlhttp3;
    if (window.XMLHttpRequest) {
        xmlhttp3 = new XMLHttpRequest();
    } else {
        xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp3.onreadystatechange=function() {
    if (xmlhttp3.readyState==4 && xmlhttp3.status==200) {

    }
}

xmlhttp3.open("GET","includes/trackEnd.php",true);
    xmlhttp3.send();
}

HTML

<script src="../includes/jsHandler.js"></script>
<script>
    window.onload = function(){ return start('<?php echo basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['PATH_INFO']); ?>');};
    window.onbeforeunload = function(){ return end(); };
    window.onclose = function(){ return end(); };
</script>

谢谢!

已解决!我正在使用 JQuery:

$(window).on('beforeunload', function(){
        return end();
      });
      $(window).on('unload', function(){
        return end();
      });