Ajax `onbeforeunload`处理程序中的XMLHttpRequest在Opera中不起作用

Ajax `onbeforeunload`处理程序中的XMLHttpRequest在Opera中不起作用,ajax,cross-browser,xmlhttprequest,onbeforeunload,Ajax,Cross Browser,Xmlhttprequest,Onbeforeunload,我有这样的脚本: <script language="JavaScript" type="text/javascript"> function enter() { this.chrono = new Date().getMilliseconds(); } function leave() { this.chrono = new Date().getMilliseconds() - this.chrono;

我有这样的脚本:

<script language="JavaScript" type="text/javascript">

    function enter() {
        this.chrono = new Date().getMilliseconds();
    }

    function leave() {
        this.chrono = new Date().getMilliseconds() - this.chrono;

        alert("test" + this.chrono);

            var blockingRequest = new XMLHttpRequest();
            blockingRequest.open("GET", "visitor_log/ajax_store_visit_duration.php?visit_duration=" + this.chrono, false); // async = false
            blockingRequest.send();

        return null;
    }

    window.onload = enter;
    window.onbeforeunload = leave;
</script>

函数enter(){
this.chrono=newdate().getmillizes();
}
函数休假(){
this.chrono=新日期().getmillizes()-this.chrono;
警报(“测试”+此.chrono);
var blockingRequest=new XMLHttpRequest();
blockingRequest.open(“GET”,“visitor\u log/ajax\u store\u visit\u duration.php?visit\u duration=“+this.chrono,false);//async=false
blockingRequest.send();
返回null;
}
window.onload=输入;
window.onbeforeunload=离开;
PHP部分(visitor\u log/ajax\u store\u visit\u duration.PHP文件):


它在Chrome中工作得很好,但在Opera中不起作用


如何使它跨浏览器?

它不应该在任何地方工作
getmillizes()
返回日期对象的毫秒部分,而不是某个最终毫秒值。该值始终小于1000。在比较你的震级时没有用处。你真正想要的是世界时间

(新日期()).valueOf()
应该为您提供一个可以使用的值

这可能是一个部分答案,因为您实际上并没有指定什么不起作用。

好吧,一点研究)谷歌(Google)在这里打开了这个讨论,所以:。这可能是相关的。
<?php

if(isset($_GET["visit_duration"]))
{
    $text = $_GET["visit_duration"];

    logtxt($text);

    echo "OK";
}
else die("application error");

function logtxt($text)
{
    $myFile = "test.txt";
    $fh = fopen($myFile, 'wb');
    fwrite($fh, $text);
    fclose($fh);
}

?>