edge javascript window.close() or self.close() not working?

hoseon-song 1 Reputation point
2022-03-20T05:48:54.813+00:00

edge developer tool console log Scripts may close only the windows that were opened by them.

If the script didn't start opening the window (something like window.open), then the script in that window seems to have been changed to a security that prevents websites that can't close the window take control of the browser and close the window.

window.open('your current page URL', '_self', '');
window.close();

edge browser not close.

solution javascript code or another api

Thanks for letting me know the part.

Please inquire above.

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,146 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. XuDong Peng-MSFT 10,101 Reputation points Microsoft Vendor
    2022-03-21T07:54:45.187+00:00

    Hi @hoseon-song ,

    window.open('your current page URL', '_self', '');
    window.close();

    edge browser not close.

    I did some testing on this issue, and with reference to the relevant documentation, I think this result is reasonable. Just refer to this doc: the latest working spec for window close(). As metioned in this doc:

    A browsing context is script-closable if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), or if it is a top-level browsing context whose session history contains only one Document.

    In my tests, the script you mentioned works correctly if the page is launched by Visual Studio or by the command line (created by script): msedge.exe www.google.com. Conversely, pages opened manually by the user cannot be closed by script(not initial interface when opening browser ). This is all as described.

    Regards,
    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.