代码一: 在IE好使,在qq浏览器不好使
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>nihao</title>
<script language="javascript">
function htmer()
{
alert("欢迎再次光临!");
}
</script>
</head>
<body οnbefοreunlοad="return htmer();">
</body>
</html>
代码二: 在IE好使,在qq浏览器不好使
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>nihao</title>
<script language="javascript">
window.onbeforeunload = function()
{
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey)
{
alert("是关闭而非刷新");
window.event.returnValue = "dsfdsf"; // 这里可以放置你想做的操作代码
}else
{
alert("是刷新而非关闭");
}
}
</script>
</head>
<body>
</body>
</html>
代码三: 在IE好使,在qq浏览器不好使
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>nihao</title>
<script language="javascript">
function getEvent() {
if(document.all) return window.event;
func = getEvent.caller;
while(func != null) {
var arg0 = func.arguments[0];
if(arg0) {
if((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) return arg0;
}
func = func.caller;
}
return null;
}
function ConfirmClose() {
if(window.event)
window.event.returnValue = "确认关闭?";
else
getEvent().preventDefault();//for firefox
}
window.onbeforeunload = function() {
ConfirmClose();
}
</script>
</head>
<body>
</body>
</html>
代码四: 在IE好使,在qq浏览器好使,但是不能定住,出来了提示语,没等点确定按钮,浏览器就关掉了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>nihao</title>
<script type="text/javascript">
function close(evt) //author: sunlei
{
var isIE=document.all?true:false;
evt = evt ? evt :(window.event ? window.event : null);
if(isIE){//IE浏览器
var n = evt.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && evt.clientY<0 || evt.altKey){
alert(1);
alert("是关闭而非刷新1");
window.event.returnValue = "确认关闭?";
}
else{
alert(2);
alert("是刷新而非关闭1");
}
}
else{//火狐浏览器
if(document.documentElement.scrollWidth!=0) {
alert("是刷新而非关闭2");
alert(2);
}
else {
alert("是关闭而非刷新2");
}
}
}
</script>
</head>
<body οnunlοad="close(event);">
</body>
</html>
代码五: 在IE好使,在qq浏览器好使,但是不能定住,出来了提示语,没等点确定按钮,浏览器就关掉了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>nihao</title>
<script type="text/javascript">
$(window).bind('beforeunload',function(){
if ( /Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) {
if(confirm('您的内容尚未保存,确定要离开本页吗?')){
history.go();
} else{
window.setTimeout(function() { window.stop(); }, 1);
}
} else{
return '您的内容尚未保存,确定要离开本页吗?';
}
});
</script>
</head>
<body οnunlοad="close(event);">
</body>
</html>
代码六: 在IE好使,在qq浏览器刷新好使,关闭不好使
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>nihao</title>
<script>
var UnloadConfirm = {};
UnloadConfirm.MSG_UNLOAD = "数据尚未保存,离开后可能会导致数据丢失\n\n您确定要离开吗?";
UnloadConfirm.set = function(a) {
window.onbeforeunload = function(b) {
b = b || window.event;
b.returnValue = a;
return a
}
};
UnloadConfirm.clear = function() {
fckDraft.delDraftById();
window.onbeforeunload = function() {}
};
UnloadConfirm.set(UnloadConfirm.MSG_UNLOAD);
</script>
</head>
<body >
</body>
</html>
代码七: 在IE好使,在qq浏览器刷新好使,关闭不好使
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>nihao</title>
<script>
function getEvent() //同时兼容ie和ff的写法, 这个方法是网上copy的
{
if(document.all) return window.event;
func=getEvent.caller;
while(func!=null){
var arg0=func.arguments[0];
if(arg0)
{
if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
{
return arg0;
}
}
func=func.caller;
}
return null;
}
function ConfirmClose() {
if(window.event)
window.event.returnValue = "在关闭窗口前确认您是否已经保存了信息!";
else
getEvent().preventDefault();//for firefox
}
function on_page_loaded() //自己定义的body的onload事件
{
try{
if(!window.onbeforeunload ) //为了不覆盖原来的onbeforeunload方法,先判断
window.onbeforeunload = ConfirmClose; //todo 增加了窗口关闭前的提示 31.
}catch(e){}
}
</script>
</head>
<body onload = on_page_loaded()>
</body>
</html>