FF无法通过window.close()关闭窗口

下面这种脚本的方法只是将当前窗口的地址变成空页面,而不是真正关闭窗口。FF下必须更改config,才能通过脚本关闭窗口。

<script>

function closeMe()
{
var win=window.open("","_self");
win.close();
}
</script>

<html>
<body>
<form>
<input type="button" name="Close"
οnclick="closeMe()" />
</form>
</body>
</html>
We can also write script like this
function winClose()
{
window.top.opener=null;
window.close();
}

or

function closeWindow()
{
window.open('','_parent','');
window.close();
}


如果你使用的是firefox浏览器必须要做以下设置
1、在地址栏输入about:config然后回车,警告确认
2、在过滤器中输入”dom.allow_scripts_to_close_windows“,双击即可将此值设为true


<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html>
<head>
<title>頁面提示</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv='Refresh' content='{$waitSecond};URL={$jumpUrl}'>
<style>
html, body{margin:0; padding:0; border:0 none;font:14px Tahoma,Verdana;line-height:150%;background:#EBEBEB}
a{text-decoration:none; color:#174B73; border-bottom:1px dashed gray}
a:hover{color:#F60; border-bottom:1px dashed gray}
div.message{margin:10% auto 0px auto;clear:both;padding:5px;border:1px solid silver; text-align:center; width:45%}
span.wait{color:blue;font-weight:bold}
span.error{color:red;font-weight:bold}
span.success{color:blue;font-weight:bold}
div.msg{margin:20px 0px}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function closeMe() 
{ 
	var userAgent = window.navigator.userAgent;
	if (userAgent.indexOf("MSIE 6") > 0) {  
    	window.opener = null; 
        window.close();
    } else if (userAgent.indexOf("MSIE") > 0) {
    	 window.open('','_self','');
         window.close();
    } else if (userAgent.indexOf("Firefox") != -1) {
		window.location.href = 'about:blank'; 
	} else if (userAgent.indexOf("Safari") != -1) {
		window.opener=null;
		window.open('','_self');
		window.close();
	} else {
		window.location.href = "{$jumpUrl}";
	}
} 

setTimeout(function() {
	if ({$closeWin}) {
		closeMe();
	} else {
		window.location.href = "{$jumpUrl}";
	}
}, 3000);	
//-->
</SCRIPT>
</head>
<body>
<div class="message">
	<div class="msg">
	<present name="message" >
	<span class="success">{$message}</span>
	<else/>
	<span class="error">{$error}</span>
	</present>
	</div>
	<div class="tip">
	<present name="closeWin" >
		頁面將在 <span class="wait">{$waitSecond}</span> 秒後自動關閉,或[<a οnclick="closeMe()">按此</a>]關閉
	<else/>
		頁面將在 <span class="wait">{$waitSecond}</span> 秒後自動跳轉,或[<a href="{$jumpUrl}">按此</a>]跳轉
	</present>
	</div>
</div>
</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值