It works fine when I use with window.open
But the most interesting thing is when I don’t use window.open() and try to close the current window it doesn’t work.
Could you please give any suggestion, how to proceed further?
Older versions of browsers have hacks to close the window, but that is coding against a browser flaw. It is talked about a lot here in the past. Modern day browsers have the flaw patched in most cases.