0

I have a problem where a page that is opened as a result of a redirect call does not execute the javascript function. This page is simply a message to indicate that an OAuth2 user session has started so I want it to close right away. It is opened by the redirect initiated by the OAuth server after processing the access_token request.

If I access this page in testing it works fine:

System.Diagnostics.Process.Start("https://localhost:44302/Home/SessionOpen");

The page loads, closes in 2 seconds.

If it is opened via the redirect it never closes...

The dead simple page:

<body  onload="closeit();">
    <div style="margin-left:auto;margin-right:auto;">
        <h3>Session has started.</h3>
        <h4>If this window does not close automatically you may close it manually.</h4>

        <script type='text/javascript'>

            function closeit(){

                setTimeout(function() {
                 window.close();
               }, 2000);
            };

        </script>
    </div>
 </body>
eric_the_animal
  • 432
  • 9
  • 19
  • 3
    browsers locked down close to prevent misuse. If you did not make the window with window.open or with the window changed domains, you most likely can not close it. I am sure there is an error/warning in the console. – epascarello Sep 12 '22 at 14:05
  • 1
    Does this answer your question? [window.close() doesn't work - Scripts may close only the windows that were opened by it](https://stackoverflow.com/questions/25937212/window-close-doesnt-work-scripts-may-close-only-the-windows-that-were-opene) – Abhishek Dutt Sep 16 '22 at 12:18

1 Answers1

-2

Have you tried taking the javascript snippet out of the body ? I think that could be the solution

  • Not going to make any difference – epascarello Sep 12 '22 at 14:06
  • So true, my bad. The problem is: "Scripts may close only the windows that were opened by them." Update: https://stackoverflow.com/questions/25937212/window-close-doesnt-work-scripts-may-close-only-the-windows-that-were-opene – Miren Igone Sep 12 '22 at 14:13
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 16 '22 at 12:18