How to close the Browser window after clicking ok on the alert box in C Sharp

Archita Agarwal 1 Reputation point
2022-05-19T18:30:56.453+00:00

How to close the Browser window after clicking ok on the alert box in C Sharp and Javascript. Please help

Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,331 Reputation points
    2022-05-19T19:42:18.057+00:00

    Depends. Refer to the documentation for how browsers work here. Specifically, if you opened the window within your main app then you can use the .close function of the window to close it in Javascript. You cannot do this from C# as that is server side code and server side code has no control over the client side.

    var window = window.open('...');
    ...
    window.close();
    

    However this only works on windows you opened via JS. If the window was opened via the user (aka they opened a tab) then the client side code cannot close it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.