关闭当前窗体报以下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. Eclipse For JavaSE安装、配置、测试

    Eclipse For JavaSE安装.配置.测试(win7_64bit) 目录 1.概述 2.本文用到的工具 3.安装与配置 4.JavaSE开发测试 5.ADT安装与Android开发测试 6. ...

  2. Jump Flood Algorithms for Centroidal Voronoi Tessellation

    Brief Implemented both CPU and GPU version, you could consider this as the basic playground to imple ...

  3. matlab练习程序(旋转矩阵、欧拉角、四元数互转)

    欧拉角转旋转矩阵公式: 旋转矩阵转欧拉角公式: 旋转矩阵转四元数公式,其中1+r11+r22+r33>0: 四元数转旋转矩阵公式,q0^2+q1^2+q2^2+q3^2=1: 欧拉角转四元数公式 ...

  4. MySQL 安装及卸载详细教程

    本文采用最新版MySQL8版本作为安装教程演示,本人亲试过程,准确无误.可供读者参考. 下载 官网下载 --> 社区免费服务版下载. 下载Windows安装程序MySQL Installer M ...

  5. MySQL 基本语句(2)

    1.创建数据库 :create database 名称 [charset 字符集 collate 校对规则] ;  如: drop database if exists `mydb` ; # 若存在就 ...

  6. MySQL线程处于Waiting for table flush的分析

      最近遇到一个案例,很多查询被阻塞没有返回结果,使用show processlist查看,发现不少MySQL线程处于Waiting for table flush状态,查询语句一直被阻塞,只能通过K ...

  7. SQL Server has encountered 1 occurrence(s) of cachestore flush for the 'Object Plans' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.

    2017-11-01 09:49:44.35 spid166 SQL Server has encountered 1 occurrence(s) of cachestore flush for th ...

  8. 通过http上下文判断是否是Ajax请求

    using System; namespace System.Web.Mvc { /// <summary>Represents a class that extends the < ...

  9. ini (ini-parser)配置文件解析 for donet

    介绍 此ini解析库适用于mono(unity3d),donet,大小在30kb左右. 开源免费:https://github.com/rickyah/ini-parser 使用示例 engine_c ...

  10. Linux中keepalived+LVS负载均衡的搭建测试

    1.1 LVS简介       LVS(Linux Virtual Server),也就是Linux虚拟服务器, 是一个自由软件项目.使用LVS技术要达到的目标是:通过LVS提供的负载均衡技术和Lin ...