问题描述
我想在浏览器关闭或标签关闭时调用注销页面我有代码在Firefox中无效,Chrome只在IE中工作
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< script type =text / javascript>
var clicked = false;
函数CheckBrowser(){
if(clicked == false){
window.location =../Security/logOut.aspx;
//浏览器关闭
}
else {
alert('false');
重定向
clicked = false;
}
}
函数Logout(){
if(clicked == false)//浏览器关闭
{
//window.location =../Security/logOut.aspx;
alert('关闭浏览器?');
var request = GetRequest();
alert('关闭浏览器'+请求);
request.open(GET,.. / Security / logOut.aspx,true);
request.send();
}
}
函数GetRequest(){
var xmlHttp = null;
try {
// Firefox,Opera 8.0 +,Safari
xmlHttp = new XMLHttpRequest();
}
catch(e){
// Internet Explorer
尝试{
xmlHttp = new ActiveXObject(Msxml2.XMLHTTP);
}
catch(e){
xmlHttp = new ActiveXObject(Microsoft.XMLHTTP);
}
}
返回xmlHttp;
}
< / script>
< / head>
< body onbeforeunload =Logout()önclick=clicked = true;>
< form id =form1runat =server>
i want to call logout page on browser close or tab close i have code that is not working in Firefox,chrome only working in IE
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var clicked = false;
function CheckBrowser() {
if (clicked == false) {
window.location = "../Security/logOut.aspx";
// Browser closed
}
else {
alert('false');
redirected
clicked = false;
}
}
function Logout() {
if (clicked == false)//browser is closed
{
//window.location = "../Security/logOut.aspx";
alert('close the browser?');
var request = GetRequest();
alert('close the browser'+request );
request.open("GET", "../Security/logOut.aspx", true);
request.send();
}
}
function GetRequest() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
//Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body onbeforeunload="Logout()" önclick="clicked=true;">
<form id="form1" runat="server">
< / form>
< / body>
< / html>
</form>
</body>
</html>
推荐答案
/////标签关闭或窗口关闭/// ///
///// tab close or window close //////
window.onbeforeunload = function()
{
your redirect page logic
}
这篇关于如何在浏览器关闭或标签关闭时调用注销页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!