1.htm: <body> 注销用户 <script> document.body.onbeforeunload=function(){logout()}; function logout() { if(confirm('确实要注销?')) { var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); var url='logout.asp?action=logout'; xmlhttp.open('post',url,false); if(xmlhttp.readyState==4) { if(xmlhttp.status!=200) { alert('注销失败'+xmlhttp.statusText); event.returnValue=false; } } } } </script> </body>logout.asp:<% if request("action")="logout" then session.abandon end if %>
<script language="javascript"> window.onbeforeunload = function() //author: meizz { var n = window.event.screenX - window.screenLeft; var b = n > document.documentElement.scrollWidth-20; if(b && window.event.clientY < 0 || window.event.altKey) { var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("GET", "logout.asp?action=logout", false); xmlhttp.send(); } } </script>
<body>
注销用户
<script>
document.body.onbeforeunload=function(){logout()};
function logout()
{
if(confirm('确实要注销?'))
{
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
var url='logout.asp?action=logout';
xmlhttp.open('post',url,false); if(xmlhttp.readyState==4)
{
if(xmlhttp.status!=200)
{
alert('注销失败'+xmlhttp.statusText);
event.returnValue=false;
}
}
}
}
</script>
</body>logout.asp:<%
if request("action")="logout" then
session.abandon
end if
%>
window.onbeforeunload = function() //author: meizz
{
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey)
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", "logout.asp?action=logout", false);
xmlhttp.send();
}
}
</script>
for(var i=0;i<2000000;i++)
{
;
}
<Script language='javascript'>
setTimeout('function aa()',1000) //1秒后执行一次,以后不在执行
</Script>不知道能否满足你 的要求; vivianfdlpw() 和 meizz(梅花雪)的方法也是不错的,个人觉得又要创建 OBJ
ActiveXObject("Microsoft.XMLHTTP");比较郁闷。如果解决不了只能想一种变通的办法了,比如:onbeforeunload的时候,当用户确定要注销
触发执行一个隐藏页面,在该页面(你的logout页面)的onload后进行一些必要的(全局)变量判断
之后再去操作(关闭或者不关闭)opener页面,也就是你的onbeforeunload的页面。没有测试,只是一条思路,仅供参考!