简体   繁体   English

关闭 angular 中的浏览器选项卡(窗口)

[英]Close browser tab (window) in angular

I there any trick that I can use to close browser tab (window) in angular.我有任何技巧可以用来关闭 angular 中的浏览器选项卡(窗口)。 most of methods I tried are not working.我尝试过的大多数方法都不起作用。 the error I got is "scripts may close only the windows that were opened by them".我得到的错误是“脚本只能关闭它们打开的 windows”。 help to ignore this帮助忽略这一点

The Window interface represents a window containing a DOM document; Window 接口表示一个包含 DOM 文档的 window; the document property points to the DOM document loaded in that window. document 属性指向 window 中加载的 DOM 文档。

A global variable, window, representing the window in which the script is running, is exposed to JavaScript code.一个全局变量 window 代表正在其中运行脚本的 window,它暴露给 JavaScript 代码。

Where the window.parent property returns the immediate parent of the current window, window.top returns the topmost window in the hierarchy of window objects. Where the window.parent property returns the immediate parent of the current window, window.top returns the topmost window in the hierarchy of window objects.

You can simply use the following code:您可以简单地使用以下代码:

window.top.close();

The Window self() property is used for returning the current window. Window self()属性用于返回当前 window。 It is generally used for comparison purposes while using other functions such as top() .它通常用于比较目的,同时使用其他函数,例如top()

You can simply use the following code:您可以简单地使用以下代码:

window.self.close(); 

Warning!警告!

Sometimes you can't close the current window in Firefox because you didn't open it.有时您无法关闭当前 Firefox 中的 window 因为您没有打开它。 Most people have their browser set to open new windows in a new tab, and you can't prevent the menu bar etc in a tab window.大多数人的浏览器设置为在新选项卡中打开新的 windows,并且您无法阻止选项卡 window 中的菜单栏等。

If you use close() method, This method can only be called on windows that were opened by a script using the Window.open() method.如果使用close()方法,则只能在使用Window.open()方法的脚本打开的 windows 上调用此方法。 If the window was not opened by a script, an error similar to this one appears in the console:如果 window 不是通过脚本打开的,控制台中会出现类似这样的错误:

Scripts may not close windows that were not opened by script.脚本不能关闭不是由脚本打开的 windows。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM