我有这样的脚本:
<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>
PHP 部分(visitor_log/ajax_store_visit_duration.php 文件):
<?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);
}
?>
它在 Chrome 中完美运行,但在 Opera 中无法运行。
如何让它跨浏览器?