js关闭当前窗口报错Scripts may close only the windows that were opened by them

这篇具有很好参考价值的文章主要介绍了js关闭当前窗口报错Scripts may close only the windows that were opened by them。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、问题

js关闭当前窗口报错Scripts may close only the windows that were opened by them,JS,# 浏览器,javascript,前端,window.close

Chrome浏览器中调用window.close()关闭当前页面时浏览器控制台报出 Scripts may close only the windows that were opened by them. 且无法关闭当前页面。

先上结论:不是通过JS打开的浏览器标签,都不能通过window.close()来关闭当前页面

二、原因

MDN对于window.close()的解释如下所示:

js关闭当前窗口报错Scripts may close only the windows that were opened by them,JS,# 浏览器,javascript,前端,window.close

文章里说,close只能关闭用在JS脚本里用open方法打开的窗口。因此下面的代码有效。

var win = window.open("https://www.oschina.net");
win.close();

或者说在窗口A执行代码

window.open("http://example.com")

然后在新创建的example.com窗口执行下面的代码也可以关闭。

window.close()

三、解决

在当前页面自身通过 window.open()方法打开一个空白页面
调用 window.close()关闭

window.open("about:blank", "_self")
window.close();

四、最后

本人每篇文章都是一字一句码出来,希望对大家有所帮助,多提提意见。顺手来个三连击,点赞👍收藏💖关注✨,一起加油☕文章来源地址https://www.toymoban.com/news/detail-806804.html

到了这里,关于js关闭当前窗口报错Scripts may close only the windows that were opened by them的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Mac系统brew报错“The GitHub credentials in the macOS keychain may be invalid”解决

    报错信息如下: $ brew search nginx Warning: Error searching on GitHub: GitHub API Error: Requires authentication The GitHub credentials in the macOS keychain may be invalid. Clear them with:   printf \\\"protocol=httpsnhost=github.comn\\\" | git credential-osxkeychain erase Create a GitHub personal access token: https://github.com/settings/tokens/new?sco

    2024年02月10日
    浏览(22)
  • Mac OS下 使用 osascript 指令,执行完可执行程序后,关闭当前已结束的终端(Terminal)窗口)

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 最近在工作中需要使用shell 脚本的可执行程序,在shell里调用完成一些其他功能。Mac os下 执行的时候是调用终端(Terminal)。执行完成后会有一个已结束终端进程界面,一直在桌面显示,每次都需要手动

    2024年02月11日
    浏览(14)
  • 解决Docker报错:This error may indicate that the docker daemon is not running.

           成功安装完docker【安装过程见上一篇Windows安装docker_up_xin的博客-CSDN博客】后的第二天就遇到了问题,进入PowerShell后报错如下:       网上常见的解决方法是在Service Windows GUI重启docker desktop service,或者使用 DockerCli.exe -SwitchDaemon命令,但是都没能解决         网

    2024年02月11日
    浏览(17)
  • 【Unity报错】Some objects were not cleaned up when closing the scene.

    Unity结束运行的时候报错Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?) 结束运行的时候突然报错,有概率,有时候有有时候没有 结束运行的时候在OnDestroy中调用了Mono的单例类,但是呢OnDestroy调用次序是不同的,有可能A先B后,也有可能是B先

    2024年02月02日
    浏览(17)
  • ISE下载程序报错A problem may exist in the hardware configuration--解决方法(亲身踩雷)

    在用ISE下载程序的时候一直报错:iMPACT:Can not find cable, check cable setup iMPACT:A problem may exist in the hardware configuration. Check that the cable, scan chain, and power connections are intact, that the specified scan chain configuration matches the actual hardware, and that the power supply is adequate and delivering the correct vo

    2024年02月09日
    浏览(13)
  • 报错:The Tomcat connector configured to listen on port xxxx failed to start. The port may already be

    APPLICATION FAILED TO START Description: The Tomcat connector configured to listen on port xxxx failed to start. The port may already be in use or the connector may be misconfigured. Action: Verify the connector’s configuration, identify and stop any process that’s listening on port xxxx, or configure this application to listen on another port. 原因:

    2024年02月12日
    浏览(17)
  • 项目依赖安装node-sass@^4.14.1 run “node scripts/install.js“报错问题解决

    很久没运行的项目突然依赖下载报错,让我很头疼,之前都是运行正常的,于是就是开找解决办法。 依赖下载遇到的报错!!! scripts.install node-sass@^4.14.1 run “node scripts/install.js”: 大概意思就是这个地址已经不能下载了,需要你下载到本地并且做一个代理: 第一步: nod

    2024年02月20日
    浏览(19)
  • The Node.js path can contain only letters,digits,periods (.),underscores...

    The Node.js path can contain only letters,digits,periods(.),underscores(_), hyphens (-), colon (:) and backslash(); 解决办法: DevEco Studio设置Nodejs提示路径只能包含英文、数字、下划线等-CSDN博客 补充: 文件路径:C:Users***AppDataRoamingHuaweiDevEcoStudio3.1optionsother.xml 也可以在DevEco Studio中,选择路径

    2024年02月04日
    浏览(19)
  • js(javascript)中页面跳转和窗口关闭等操作

    1、self.loaction.href=\\\"/具体路径\\\" 2、location.href=\\\"/具体路径\\\" 3、windows.loaction.href=\\\"/具体路径\\\" 4、this.loaction.href=\\\"/具体路径\\\" parent.location.href=\\\"/具体路径\\\" top.location.href=\\\"/具体页面\\\" window.location.reload() 使用该方法刷新页面时,如果有数据待提交,会提示是否提交 如果页面中自定义了f

    2024年02月16日
    浏览(13)
  • 成功解决Pycharm报错:Note: you may need to restart the kernel to use updated packages.

    pycharm中 import sklearn 报错: 然后在pycharm的控制台console中使用 pip install sklearn 安装了sklearn包,使用 pip list 命令查看安装成功: 但是,最 玄学 的事情来了,明明安装成功,import却还是和刚开始一样的报错。 细看发现 pip list 的末尾有一句: 我知道jupyter怎么重启内核,但是p

    2024年02月04日
    浏览(27)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包