0

I tried the following code but it doesn't work

var win = window.open("about:blank", "_self");
  win.close();
Tungnt
  • 1
  • 3
    That would close the window you opened. Modern browsers locked down closing of windows. If you do not create the window/tab, you are most likely not going to be be closing it. – epascarello Nov 21 '22 at 01:49
  • is there any way to close the current tab without using it anymore ? – Tungnt Nov 21 '22 at 02:07
  • See [`Window.close()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/close). What exactly are your expectations? What's not working? See [ask]. – jsejcksn Nov 21 '22 at 02:14
  • i want to close the current tab but when i use window.close() the browser says ` Scripts may close only the windows that were opened by them `. I tried searching on google and tried everything but still got the error – Tungnt Nov 21 '22 at 02:38
  • [^](https://stackoverflow.com/questions/74513427/how-to-close-browsers-current-tab-using-javascript#comment131534834_74513427) @NhấtTiếuNạiHà Instead of opening a new window and closing the current one, just [reuse the current one](https://stackoverflow.com/a/1226718/438273). – jsejcksn Nov 21 '22 at 03:03
  • @jsejcksn I mean I don't need to open a new tab, just close the current tab – Tungnt Nov 21 '22 at 03:29
  • Unless I'm mistaken, this is not possible. – Eli Richardson Nov 21 '22 at 07:22
  • You can not close windows you did not create. As I said, browsers do not allow it. – epascarello Nov 21 '22 at 12:33

0 Answers0