Jan
24
在做网站的时候可能会遇到这样的情况,当客户浏览网站时,我们必须弹出个新窗口,然后把父页面先关闭掉。让访客在窗口里面操作内容。由于客户访问的第一个页面是父窗口,我们使用window.close();来实现关闭,会经常弹出个“您查看的网页正在试图关闭窗口。”的字样要您点确定才可以关闭。下面的代码可以让你实现不提示直接关闭窗口。
<!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>可行JS关闭窗口解决方案</title>
</head>
<script language="JavaScript">
<!--
function CloseWin(){
var ua=navigator.userAgent; //浏览器的类型和版本
var ie=navigator.appName=="Microsoft Internet Explorer"?true:false; //获取浏览器的名称是否是IE
//如果是IE
if(ie){
var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))));
//如果IE版本号小于5.5
if(IEversion< 5.5){
var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">';
str += '<param name="Command" value="Close"></object>';
document.body.insertAdjacentHTML("beforeEnd", str);
document.all.noTipClose.Click();
}
else{
window.opener =null;
window.close();
}
}else{
window.close();
}
}
//-->
</script>
<body>
<input type=button value=关闭 onclick="CloseWin()">
</body>
</html>
此效果在Windows xp和2003的IE上测试通过,在火狐浏览器好像不行,有需求的可以自己测试下。
<!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>可行JS关闭窗口解决方案</title>
</head>
<script language="JavaScript">
<!--
function CloseWin(){
var ua=navigator.userAgent; //浏览器的类型和版本
var ie=navigator.appName=="Microsoft Internet Explorer"?true:false; //获取浏览器的名称是否是IE
//如果是IE
if(ie){
var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))));
//如果IE版本号小于5.5
if(IEversion< 5.5){
var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">';
str += '<param name="Command" value="Close"></object>';
document.body.insertAdjacentHTML("beforeEnd", str);
document.all.noTipClose.Click();
}
else{
window.opener =null;
window.close();
}
}else{
window.close();
}
}
//-->
</script>
<body>
<input type=button value=关闭 onclick="CloseWin()">
</body>
</html>
此效果在Windows xp和2003的IE上测试通过,在火狐浏览器好像不行,有需求的可以自己测试下。
over
2008/10/10 15:22
问题解决 感谢!!
分页: 1/1
1
1
整理Ajax--XMLH


