今天找了好久网上的方法, 测试了很久其实没有真正解决浏览器区别刷新和关闭并分别处理.
测试了好久只找到IE6可以处理的方法, IE7,FIREFOX压根不起作用,先把东西放上来,以后找到方法了再来更新. 顺便悲哀一下没有真正解决问题
用户关闭页面时, 记录离开的时间, 如果是一个用户在注册,他已经输入了基本的信息比如用户名和邮箱,但是可能在第2个页面的时候他把注册页面关闭了,就可以直接处理下发送一份邮件到他已输入的邮箱里提醒他注册信息不完整.

Code
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<html>
3
<head>
4
<title> new document </title>
5
<meta name="generator" content="editplus">
6
<meta name="author" content="">
7
<meta name="keywords" content="">
8
<meta name="description" content="">
9
</head>
10
<script type="text/javascript">
11
12
function getXmlHttpObject()
13

{
14
var xmlHttps=null;
15
try
{
16
// Firefox, Opera 8.0+, Safari
17
xmlHttps = new XMLHttpRequest();
18
} catch (e)
{
19
// Internet Explorer
20
try
{
21
xmlHttps = new ActiveXObject("Msxml2.XMLHTTP");
22
} catch (e)
{
23
xmlHttps = new ActiveXObject("Microsoft.XMLHTTP");
24
}
25
}
26
return xmlHttps;
27
}
28
29
function sendInfo()
30

{
31
var xmlHttp;
32
33
xmlHttp = getXmlHttpObject();
34
xmlHttp.open("GET",'http://localhost/test/closebrower_use.php', true);
35
36
xmlHttp.onreadystatechange=function()
{
37
if (xmlHttp.readyState==4)
38
{
39
// alert(xmlHttp.responseText);
40
}
41
};
42
xmlHttp.send(null);
43
}
44
45
function close(e)
46

{
47
var n = e.screenX - window.screenLeft;
48
var b = n > document.documentElement.scrollWidth - 20;
49
50
if(b && e.clientY < 0 || e.altKey)
51
{
52
sendInfo();
53
e.returnValue = "";
54
}
55
}
56
</script>
57
58
<body onbeforeunload='javascript:close(event);'>
59
<a href="http://www.tom.com">www</a>
60
</body>
61
</html>
closebrower_use.php 用文件记录关闭页面的时间,

Code
1
<?php
2
$f = fopen('time.txt', 'a+');
3
fwrite($f, 'Leaving time:' . date('Y-m-d H:i:s') . '\n');
4
fclose($f);
5
?>