question

Bipinkumar-8803 avatar image
0 Votes"
Bipinkumar-8803 asked XuDongPeng-MSFT answered

window.close() not working in Edge browser from ASP.NET web application

Hi Expert,

We use ClientScript.RegidterStartupScript to open new window using window.open on button click and at the same time we use window.close to close the page once processing is completed.

Page.ClientScript.RegidterStartupScript(Page.Type(), "Close window","window.open(URL, name, specs);window.close();",true);

This code works in IE but not in Edge. In IE page is getting closed automatically but not in Edge.

Please help to fix this issue.

Thanks

ms-edgedotnet-aspnet-webforms
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.

TKujala avatar image
1 Vote"
TKujala answered
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.

XuDongPeng-MSFT avatar image
0 Votes"
XuDongPeng-MSFT answered

Hi @Bipinkumar-8803 ,

This code works in IE but not in Edge. In IE page is getting closed automatically but not in Edge.

As already mentioned, the main reason is that there are differences between what browsers implement.

In Internet Explorer, pages opened by window.open() are silently closed by window.close() function. There’s no attempt to check whether the back/forward stack contains only one document.

But in Edge, window.close() only succeeds if the new window/tab has an opener or if the back/forward stack contains fewer than two entries. Just refer to the dom-window-close section of the HTML Standard, and I recommend that you pay more attention to modern browsers.

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.

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.