title: How can I fetch the access code from final window?
body: <p>I'm trying to do a simple OAUTH application with the Google api.</p>
  
  <p>In the middle of the procedure I'm trying to fetch the access code from an opened window after the authorization since the opened window passes through multiple redirects. I was wondering how can I get the code from the final page before closing so I can continue with using it.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;quick demo&lt;/title&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body ng-app="app" ng-controller="ctrl"&gt;
  
  &lt;img src="folder/mGHPI.png" ng-click="login()"&gt;
  &lt;/body&gt;
  &lt;script&gt;
      var app= angular.module("app",[]);
      var url;
      var openedwindow;
      var code;
      app.controller("ctrl",function($scope,$http,$window){
          $http.get("url").then(function(response){
              url=response.data
          });
          $scope.login=function(){
              openedwindow=$window.open(url,"sign in with google","width=500px,height:700px")
              code =openedwindow.document.URL;
  
              console.log(code)
          };
          //window.opener.postMessage("my  url is :"+location.href,"*");
  
          window.onmessage = function(e){
              console.log(e)
          }
      })
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>