关闭浏览器弹出提示的兼容问题陈述
2014-04-22 22:06
274 查看
代码一: 在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 onbeforeunload="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 onunload="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 onunload="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 getEve
4000
nt() //同时兼容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>
<!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 onbeforeunload="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 onunload="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 onunload="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 getEve
4000
nt() //同时兼容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>
相关文章推荐
- onbeforeunload与onunload事件异同点总结
- JS控制显示隐藏兼容问题(IE6、IE7、IE8)
- 关闭浏览器时提示onbeforeunload事件
- Javascript解决常见浏览器兼容问题的12种方法
- 捕获页面关闭的事件onbeforeunload和onunload
- onbeforeunload与onunload事件
- Strict standards: Non-static method cls_image::gd_version() should not be called statically in
- DIV+CSS_1_兼容问题
- genymotion 此应用与您的手机不兼容
- js之Date()方法获取时间问题
- 在iphone下遇到的一些兼容性问题
- 使用onbeforeunload事件检测窗口是否刷新或关闭 .
- 浮动问题(IE6最小高度问题、双边距问题以及清理图片间隙)
- Android 解决apk覆盖安装的时候,出现安装失败,与旧版本部兼容的问题
- 轻松搞定各版本IE兼容问题,IE6,IE7,IE8,IE9,IE10,IE11
- 移动端webApp兼容问题解决
- 解决通过NuGet更新第三方包时提示不兼容的问题
- android webview图片文件上传——上传控件点击无效的解决办法
- Spring+Quartz的版本兼容问题
- Android 判断通知栏权限的问题