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

Bipin kumar 1 Reputation point
2022-06-05T03:21:22.097+00:00

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

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,114 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,245 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. T. Kujala 8,696 Reputation points
    2022-06-05T04:34:10.68+00:00
    1 person found this answer helpful.
    0 comments No comments

  2. XuDong Peng-MSFT 10,096 Reputation points Microsoft Vendor
    2022-06-06T09:28:37.483+00:00

    Hi @Bipin kumar ,

    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.

    0 comments No comments