JS倒计时结束关闭页面:Scripts may close only the windows that were opened by it.
来源:互联网 发布:数据统计分析基础 编辑:程序博客网 时间:2024/06/05 03:32
在应用中,经常看见支付成功之后,会有倒计时关闭网页。去年我写过一个关闭网页的小demo
- HTML
<p class='autoClose'>5S后关闭此页面</p>
- JS
function task(){ var n=$('.autoClose').html()[0]; if(n>1){//如果n>1 n--;//n-1 $('.autoClose').html($('.autoClose').html().replace(/^\d/,n)); }else{//否则 window.close(); } }} //将task放入周期性定时器,时间间隔为1000 var timer=setInterval(task,1000);
当时写的时候是好使的,现在在本地也是好使的。。。可是一到服务器就不行了,出现下图的问题
Scripts may close only the windows that were opened by it.
查了下资料,说是在新版的浏览器中不支持此方法了。详细解释看本篇文章,我写下我的解决办法,在不支持window.close()
的页面,将他变为空白页。改过之后是这样的:
function task(){ var n=$('.autoClose').html()[0]; if(n>1){//如果n>1 n--;//n-1 $('.autoClose').html($('.autoClose').html().replace(/^\d/,n)); }else{//否则 var userAgent = navigator.userAgent; if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) { window.location.href="about:blank"; } else { window.opener = null; window.open("", "_self"); window.close(); } }} //将task放入周期性定时器,时间间隔为1000 var timer=setInterval(task,1000);
0 0
- JS倒计时结束关闭页面:Scripts may close only the windows that were opened by it.
- js 关闭页面(Scripts may close only the windows that were opened by it.)
- js点击关闭当前浏览器Scripts may close only the windows that were opened by it.
- window.close()提示 "Scripts may close only the windows that were opened by it"
- [乐意黎原创] window.close()提示 "Scripts may close only the windows that were opened by it"
- window.close() doesn't work - Scripts may not close windows that were not opened by script.
- Application did not close the cursor or database object that was opened here 异常
- Why is the window.close() works in IE browser but not FireFox? "Warning: Scripts may not close windo
- CCS5导入工程时出错:Issues that may require your attention were encountered while importing the projects
- The AssetBundle could not be loaded because it references scripts that are not compatible ...
- resolve the issue of "the machine is dead" caused by that /dev/ttyUSB2 cann't be opened
- Fixing "The following VMware kernal modules have been found on your system that were not installed by the VMware installer."
- Fixing "The following VMware kernal modules have been found on your system that were not installed by the VMware installer."
- windows.close()关闭IE时不提示的JS方法
- JavaScript无提示关闭当前页面窗口,兼容IE/Firefox/Chrome (Close the current page window without confirm by JavaScript, support all browsers)
- js实现关闭本页面,window.close()真的不能关闭chorm浏览器的页面吗?
- window.close() 直接关闭页面
- When connecting to SQL Server 2005, this failure may be caused by the fact that under the defa
- swing的初步学习(读书笔记)
- 剑指offer 34. 丑数
- 发财树怕晒吗
- 堆栈在C语言中的定义(单片机的中堆栈相当于栈)
- 错排思想
- JS倒计时结束关闭页面:Scripts may close only the windows that were opened by it.
- CodeForces 805A Fake NP
- Hibernate配置文件hbm主键的generator可选项
- Java连接数据库
- DB2使用命令行连接远程数据库
- Web应用安全威胁与防治--基于OWASP TOP 10 与ESAPI
- WebGL摄像机详解之一:模型、视图和投影矩阵变换的含义
- 人脸检测
- 去哪儿的用户画像构建策略及应用实践