网页QQ web2关闭浏览器提示效果
好久不上CSDN了。 今天发现个东西。 希望各位帮忙。嘿
QQ推出了网页版本。登录网址:http://web2.qq.com
今天我使用FireFox登录后。使用了一下,感觉还不错。只是功能没有那么全。
当我点Firefox右上角关闭浏览器或关闭QQ所在的标签时。 它会提示是否退出?
我记的Firefox 没有标签关半和浏览器关闭时的响应函数吧。 (还是我孤陋寡闻。。。)
请教的功能应该怎么实现的。 大虾们指教下。
大家可以登录网页QQ 试试。 嘿嘿
[解决办法]
<body onbeforeunload="event.returnValue='确定退出吗'" >
</body>
不是所有浏览器全支持
[解决办法]
在Safari下的JS控制台找了好久没找到onbeforeunload,我的妈呀,webqq内部的文档对象太复杂了。。是学习js的好东东!
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>EQQ Proxy 2011-03-31-02</title>
</head>
<body>
<script>
document.domain = "qq.com";
// 兼容不同浏览器的 Adapter 适配层
if(typeof window.XMLHttpRequest === "undefined"){
window.XMLHttpRequest = function(){
return new window.ActiveXObject(navigator.userAgent.indexOf("MSIE 5") >=0 ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
};
}
/**
* 这是Ajax对象名字空间的一个方法
*
* @memberOf Http
* @method ajax
*
* @param {Object} options 一个配置对象
* @return {Object} ajax 返回一个ajax对象
*/
var ajax = function(uri, options){
var httpRequest,
httpSuccess,
timeout,
isTimeout = false,
isComplete = false;
options = {
method: options.method
[解决办法]
"GET",
data: options.data
[解决办法]
null,
arguments: options.arguments
[解决办法]
null,
onSuccess: options.onSuccess
[解决办法]
function(){},
onError: options.onError
[解决办法]
function(){},
onComplete: options.onComplete
[解决办法]
function(){},
//尚未测试
onTimeout: options.onTimeout
[解决办法]
function(){},
isAsync: options.isAsync
[解决办法]
true,
timeout: options.timeout ? options.timeout : 30000,
contentType: options.contentType ? options.contentType : "utf-8",
type: options.type
[解决办法]
"xml"
};
uri = uri
[解决办法]
"",
timeout = options.timeout;
httpRequest = new window.XMLHttpRequest();
httpRequest.open(options.method, uri, options.isAsync);
//设置编码集
//httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
httpRequest.setRequestHeader("Content-Type",options.contentType);
/**
* @ignore
*/
httpSuccess=function(r){
try{
return (!r.status && location.protocol == "file:")
[解决办法]
(r.status>=200 && r.status<300)
[解决办法]
(r.status==304)
[解决办法]
(navigator.userAgent.indexOf("Safari")>-1 && typeof r.status=="undefined");
}catch(e){}
return false;
}
//httpRequest.UPDATE_TIME_STAMP = "20110331001";
httpRequest.onreadystatechange=function (){
if(httpRequest.readyState==4){
if(!isTimeout){
var o={};
o.responseText = httpRequest.responseText;
o.responseXML = httpRequest.responseXML;
o.uri=uri;
o.arguments=options.arguments;
o.status= httpRequest.status;
o.data = options.data;
if(httpSuccess(httpRequest)){
if(options.type === "script"){
eval.call(window, data);
}
try{
if(options && options.onSuccess){
options.onSuccess(o);
}
}catch(e){}
}else{
try{
options.onError(o);
}catch(e){}
}
try{
options.onComplete(o);
}catch(e){}
}
isComplete = true;
//删除对象,防止内存溢出
httpRequest = null;
}
};
httpRequest.send(options.data);
window.setTimeout(function(){
var o;
if(!isComplete){
isTimeout = true;
o={};
o.uri=uri;
o.arguments=options.arguments;
if(httpRequest){
httpRequest.abort();
httpRequest = null;
}
try{
options.onTimeout(o);
options.onComplete(o);
}catch(e){}
}
}, timeout);
return httpRequest;
};
function GetRequest(){
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if(url.indexOf("?") != -1)
{
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++)
{
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
var urlParam = GetRequest();
//这里为了安全,不直接传回调函数过来,这里做一层map
if(urlParam["callback"]){
parent.alloy.ajaxProxyCallback(parseInt(urlParam["callback"]), parseInt(urlParam["id"]));
}
</script>
</body>
</html>
window.onbeforeunload=function(e){
e=e
[解决办法]
window.event;
e.returnValue="\n真的离开??\n"
//do something。。。。。。。
}