title: Login with popup
body: <p>I'm working in MVC and I want to be able to implement a login system using a popup window.</p>
  
  <p>The part I am stuck on is, when a successful login occurs in the popup window - it then needs to close and a redirect has to happen on the main page. I am struggling to achieve this as I am running into a whole load of scope issues with JQuery.</p>
  
  <p>I create my popup window with this:</p>
  
  <pre><code>window.open('@Url.Action("Login", "User", null, "http")', 'Login', 'height=500,width=300');
  </code></pre>
  
  <p>It would be nice to be able to prepend <code>var window =</code> to the above code so that I was able to refrence the window I want to close on successful login - but that variable is out of scope from my Login window:</p>
  
  <pre><code>@{
    ViewBag.Title = "Login";
  }
  
  &lt;h2&gt;Login&lt;/h2&gt;
  
  &lt;p id="login-fail" style="display:none"&gt;Incorrect username/password&lt;/p&gt;
  
  @using (Html.BeginForm()) {
    @Html.LabelFor(x =&gt; x.Email, new { id = "txt-email" })
    @Html.TextBoxFor(x =&gt; x.Email)
    &lt;br /&gt;
    &lt;label for="txt-password"&gt;Password&lt;/label&gt;
    &lt;input id="txt-password" type="password" /&gt;
    &lt;input type="submit" value="Login" /&gt;
  }
  
  
  &lt;script type="text/javascript"&gt;
    $(function () {
      var success = '@Model.Success';
      if (success == "True") {
        loginSuccess(this.window);
      }
      var failed = '@Model.Failed';
      if (failed == "True") {
        $("#login-fail").show();
      }
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>I refresh the partial view when the form is posted and Jquery checks for success when the page is loaded. On success, I then try to pass the current window to a js function called loginSuccess:</p>
  
  <pre><code>function loginSuccess(elem) { // successful login has occurred
    elem.close();
    window.location = //getRedirect;
  }
  </code></pre>
  
  <p>So far I cannot get the popup window to close, and then I need to focus to my main window when I set my redirect.</p>
  
  <p>I have a javascript file called functions that both my main window and popup each reference. However, the js that creates the popup window is not in the functions file and the window variable is not available to either window. </p>
  
  <p>Long story short, I am attempting to mock the LinkedIn login process, so the code that creates the popup window is invoked by calling <code>IN.UI.Authorize().place();</code> - which rules out returning the window variable as the code has to remain the same whether I use my mock LinkedIn or the real one.</p>
  
  <p>Would really appreciate any help with this, particularly referencing the popup window somehow and then refocusing to the main window for the redirect.</p>