window.close()提示 "Scripts may close only the windows that were opened by it"
2015-06-26 15:26
639 查看
由于在脚本中使用了 window.close(), 当前非弹出窗口在最新版本的chrome和firefox里总是不能关闭,而在 IE中是可以关闭的 。
在console中弹出提示”Scripts may close only the windows that were opened by it”
首先,什么是非弹出窗口呢?
非弹出窗口,即是指(opener=null 及 非window.open()打开的窗口,比如URL直接输入的浏览器窗体, 或由其它程序调用产生的浏览器窗口)。
其次,window.close() 怎么理解呢?
可参考 https://developer.mozilla.org/en-US/docs/Web/API/window.close
在某些实际应用中,window.close() and self.close() 是不能关闭非弹出窗口(opener=null及非window.open()打开的窗口)。
以下代码也只是保证了在ie下不再出现确认对话框, 对chrome和ff不能关闭是没有任何作用的
https://developer.mozilla.org/en-US/docs/Web/API/window.close
https://productforums.google.com/forum/#!topic/chrome/GjsCrvPYGlA
http://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome
最后结论:
在新弹出的标签页中去掉”关闭页面”的按钮, 很多网站包括百度等都规避了window.close()
在console中弹出提示”Scripts may close only the windows that were opened by it”
首先,什么是非弹出窗口呢?
非弹出窗口,即是指(opener=null 及 非window.open()打开的窗口,比如URL直接输入的浏览器窗体, 或由其它程序调用产生的浏览器窗口)。
其次,window.close() 怎么理解呢?
可参考 https://developer.mozilla.org/en-US/docs/Web/API/window.close
在某些实际应用中,window.close() and self.close() 是不能关闭非弹出窗口(opener=null及非window.open()打开的窗口)。
以下代码也只是保证了在ie下不再出现确认对话框, 对chrome和ff不能关闭是没有任何作用的
<script type="text/javascript"> function closeWP() { var Browser = navigator.appName; var indexB = Browser.indexOf('Explorer'); if (indexB > 0) { var indexV = navigator.userAgent.indexOf('MSIE') + 5; var Version = navigator.userAgent.substring(indexV, indexV + 1); if (Version >= 7) { window.open('', '_self', ''); window.close(); } else if (Version == 6) { window.opener = null; window.close(); } else { window.opener = ''; window.close(); } } else { window.close(); } } </script>
https://developer.mozilla.org/en-US/docs/Web/API/window.close
https://productforums.google.com/forum/#!topic/chrome/GjsCrvPYGlA
http://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome
最后结论:
在新弹出的标签页中去掉”关闭页面”的按钮, 很多网站包括百度等都规避了window.close()
相关文章推荐
- tomcat均衡负载
- 【Hadoop】4、Hadoop安装之cloudera manager(2)
- CentOS 修改ls目录的颜色
- Xshell常用配置
- linux下(Ubuntu、centos)添加永久静态路由的方法
- OpenCV 高斯模糊
- Nginx日志管理和切割
- centos 7 修改主机名的方法
- Windows下Nginx的安装与配置
- /etc/profile、~/.bash_profile等几个文件的执行过程
- 网站用户密码加密
- 配置Nginx服务器防止Flood攻击的方法
- centos 各种下载包的含义
- Android睡眠唤醒机制--系统架构
- Linux下rar 命令压缩和解压详解
- 关于linux定时操作cron的理解
- linux操作系统下怎样解压rar文件
- Linux/ubuntu下搭建svn服务器,安装eclipse subclipse插件小结
- linux解压命令大全
- Linux 与 Linux Windows 文件共享