1

I try many ways to close the browser window with angular 13 but don't work with me

I try this :

var win = window.open("about:blank", "_self");
win.close();
 window.opener = null;
    window.open("", "_self");
    window.close();
    window.location.href="javascript:window.close()"
  • Does this answer your question? [window.close and self.close do not close the window in Chrome](https://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome) – araisch Mar 29 '22 at 10:15

1 Answers1

2

You only have the power to close a tab if you were the one that opened that tab.

In the following example the close button will only work after opening a new tab using the link.

export class MyComponent {
  close() {
    window.close();
  }
}
<a href="http://localhost:4200" target="blank">Open New Tab</a><br />
<button (click)="close()">close</button>

From this article: https://www.thesitewizard.com/javascripts/close-browser-tab-or-window.shtml

On all modern browsers, the web page to be closed must be the first in that window/tab's session history.

And further:

Modern browsers will also resist your attempt to trick them into thinking that an existing window/tab was opened with JavaScript when it was not.

This is done to protect the user's session history.

Chris Hamilton
  • 9,252
  • 1
  • 9
  • 26