question

hoseonsong-4003 avatar image
0 Votes"
hoseonsong-4003 asked Alex-3722 published

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

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.

ms-edge
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

XuDongPeng-MSFT avatar image
0 Votes"
XuDongPeng-MSFT answered Alex-3722 published

Hi @hoseonsong-4003 ,

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @hoseonsong-4003,

May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·

Hi,

On Firefox there is a way to disable this behavior. Is there one for Edge as well?

Regards,
Alex

0 Votes 0 ·