/ * ** * ** * **** test1.php * ** * ** * *** /我创建一个简单的例子来理解问题,下面是test1.php文件的内容
<html><head></head><body>
<script language="javascript" type="text/javascript">
var xhrHttp;
function getXHRObject() {
var obj = false;
try {
obj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
obj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
try {
obj = new XMLHttpRequest();
}
catch (e) {
return false;
}
}
}
return obj;
}
function unloadFCT() {
xhrHttp = getXHRObject();
xhrHttp.open("GET", "ajaxCall.php", false);
}
var val = navigator.userAgent.toLowerCase();
if(val.indexOf("msie") > -1){
window.attachEvent('onbeforeunload', unloadFCT);
}
else{
window.onunload = unloadFCT;
}
当您关闭此窗口时,将在 ajaxCall.php 所在的位置创建一个新文件
/ * ** * ** * **** ajaxCall.php * ** * ** * *** /
<?php
$handle = fopen("myFile_".time().".txt", 'a+');
fwrite($handle, "simple message...");
?>
/ * ** * ** * **** test2.php * ** * /
<html><head></head><body>
<script language="javascript" type="text/javascript">
var xhrHttp;
function f(){
unloadFCT();
window.close();
}
function getXHRObject() {
var obj = false;
try {
obj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
obj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
try {
obj = new XMLHttpRequest();
}
catch (e) {
return false;
}
}
}
return obj;
}
function unloadFCT() {
xhrHttp = getXHRObject();
xhrHttp.open("GET", "ajaxCall.php", false);
}
var val = navigator.userAgent.toLowerCase();
if(val.indexOf("msie") > -1){
window.attachEvent('onbeforeunload', unloadFCT);
}
else{
window.onunload = unloadFCT;
}
执行 unloadFCT() 函数的代码并关闭此窗口!!!
/ * ** * ** * ** * ** *问题* ** * ** * ** * * /
你能告诉我test2.php有什么问题吗?我希望 f() 函数执行 unloadFCT() 的代码并关闭当前窗口。