问题:跳转后的页面执行window.close()方法失败

在测试中遇到一个问题,当从其他页面跳转到当前页面时,使用window.close()方法无法关闭窗口。浏览器控制台显示警告:Scripts may close only the windows that were opened by it。原因是浏览器认为该页面非自身打开,故不允许关闭。解决方案是在window.close()前添加window.location.href="about:blank",这样可以成功关闭窗口。
摘要由CSDN通过智能技术生成

  测试中发现下面这个HTML单独运行时可以正确close,但是当其他页面跳转过来,则不能正确关闭。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>欢迎再次使用</title>
		<style>
			body{
				background: url("img/exit_bg.jpg") no-repeat;
				height:100%;
				width:100%;
				overflow: hidden;
				background-size:cover;
			}
			#exitDiv{
				width:100%;
            	height:100%;
				line-height: 300px;
				text-align: center;
				font-family: arial;
				font-size: 40px;
				color: Orange;
			}
			#tipDiv{
				text-align: center;
				color: OrangeRed;
			}
		</style>
		<script type="text/javascript">
			var start;
			var timeCount = 3;
			function exitFun(){
				console.log(timeCount);
				if(timeCount <= 0){
					console.log("yes");
  					window.close();
					console.log("关闭了!");
				}
				document.getElementById("tip").innerText &#
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值