关闭当前窗体报以下js错误:

Scripts may close only the windows that were opened by it

(脚本只能关闭由它打开的窗口)


使用场景,在js中关闭页面的js,如下:

window.opener = null;
window.open('', '_self');
window.close();

未能通过。

关闭页面的代码写在一个ajax返回的结果中的,如下:

$.ajax({
type: 'post',
url: "url",
success: function (data) {
if (data.isOut) {
window.opener = null;
window.open('', '_self');
window.close();
}
else {
alert(data.msg);
}
},
error: function (err) {
alert("异常:" + err);
}
})

解决办法:

window.location.href="about:blank";
window.close();

成功关闭。

Scripts may close only the windows that were opened by it的更多相关文章

  1. 脚本不得关闭非脚本打开的窗口。Scripts may close only the windows that were opened by it

    今天脚本了里写了一句话: window.close() 但是浏览器却报了警告提示:Scripts may close only the windows that were opened by it,而 ...

  2. scripts may close only the windows that were opened by it 浏览器JS控制无法关闭当前页面

    非window.open形式打开的子页面用js的window.close在chrome下就会提示scripts may close only the windows that were opened ...

  3. js 关闭页面(Scripts may close only the windows that were opened by it.)

    传送http://blog.csdn.net/kuangfengbuyi/article/details/52052301 js关闭当前页面,当该页面不是其他页面打开的,而是直接输入url, 直接用w ...

  4. js关闭浏览器的tab页(兼容)

    由于在脚本中使用了 window.close(), 当前非弹出窗口在最新版本的chrome和firefox里总是不能关闭,而在 IE中是可以关闭的 . 在console中弹出提示"Scrip ...

  5. 【温故而知新-Javascript】窗口效果 (全屏显示窗口、定时关闭窗口)

    1.全屏显示窗口 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  6. chrome浏览器关闭标签页面

    chrome浏览器关闭标签页提示:Scripts may close only the windows that were opened by it. 解决办法:通过open方法进行关闭. open( ...

  7. 【经验】JavaScript

    1.function closeWin(){             window.open('','_self');       window.opener=null;  //    window. ...

  8. chrome JS关闭当前页无效问题

    如果没有父窗口,JS中 window.opener = null; window.open("", "_self"); window.close(); 对chr ...

  9. 谷歌浏览器禁止window.close的问题

    当一个窗口不是通过window.open或者window.showModalDialog打开的时候,调用JS的window.close() 谷歌浏览器会提示如下警告,并拒绝执行 Scripts may ...

随机推荐

  1. linux连接数过多,导致ping包丢包的问题解析

    1.首先要明确,无论是tcp, udp, raw等这些都要占用socket, 那么就涉及到连接数的问题. 所以,linux连接数的问题,不仅仅是tcp连接数. 2.查看当前系统中所有的socket 连 ...

  2. 快速开发跨平台应用之Xamarin技术

    Xamarin 介绍 Xamarin 是一个允许开发人员有效创建可跨 iOS.Android.Windows 应用程序的开发工具集.Xamarin是免费且开源的,遵循 MIT (麻省理工学院许可证)协 ...

  3. 【爬虫】使用xpath与lxml移除特定标签

    移除标签的两种方式 可以用xpath定位 for bad in html.xpath(".//table"): bad.getparent().remove(bad) 参考:htt ...

  4. 计算机图形学(第2版 于万波 于硕 编著)第45页的Bresenham算法有错误

    计算机图形学(第2版 于万波 于硕 编著)第45页的Bresenham算法有错误: 书上本来要写的是以x为阶越步长的方法,但是他写的是用一部分y为阶越步长的方法(其实也写的不对),最后以x为阶越步长的 ...

  5. [20190225]删除tab$记录的恢复5.txt

    [20190225]删除tab$记录的恢复5.txt --//昨天下午看了链接https://blog.csdn.net/Enmotech/article/details/87834503,大概知道对 ...

  6. c/c++ allocator 使用

    allocator 使用 作用:只开辟空间,不调用构造函数 操作一览表 allocator<T> a 定义一个名为a的allocator对象,它可以为类型为T的对象分配内存 a.alloc ...

  7. Windows重启显卡驱动热键说明

    Windows 有一个秘密的快捷键,可以重启显卡驱动程序.如果你的电脑经常“冻屏”,可以在重启电脑之前试试这个快捷键,它可以修复冻屏,否则就只能强制重启电脑了. 这个组合快捷键将重启 Win10 和 ...

  8. Docker: docker container常用命令实战

    容器管理,容器常用选项 选项 描述 -i, –interactive 交互式 -t, –tty 分配一个伪终端 -d, –detach 运行容器到后台 -e, –env 设置环境变量 -p, –pub ...

  9. 【Teradata】 TPT基础知识

     1.TPT Description Teradata Parallel Transporter (TPT) is client software that performs data extract ...

  10. ZooKeeper Administrator's Guide A Guide to Deployment and Administration(吃别人嚼过的馍没意思,直接看官网资料)

    Deployment System Requirements Supported Platforms Required Software Clustered (Multi-Server) Setup ...