title: How to get redirected url in C# WebBrowser Control
body: <p>I have a webpage that loads, does some calculations and then does a JavaScript redirect to another webpage. It looks something like this:</p>
  
  <p><strong><a href="http://www.mysite.com/startpage.html" rel="nofollow noreferrer">http://www.mysite.com/startpage.html</a></strong></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head runat="server"&gt;
  $(document).ready(function() {
      window.location = "http://www.mynewurl.com";
  });
  &lt;/head&gt;
  &lt;body&gt;
  Something
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now I have an asp.net MVC app that loads a WebBrowser control and my <b>goal</b> is to be able to retrieve <code>http://www.mynewurl.com</code> from within my C# WebBrowser control.</p>
  
  <p>My WebBrowser code looks like:</p>
  
  <pre><code>WebBrowser webBrowser = new WebBrowser
                                      {
                                          ScrollBarsEnabled = false,
                                          Size = new Size(Width, Height),
                                          ScriptErrorsSuppressed = true
                                      };
  
      webBrowser.NewWindow += WebBrowserNewWindow;
      webBrowser.Navigate("http://www.mysite.com/startpage.html");
  
  
      //wait for it to load
      while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
      {
          Application.DoEvents();
      }
  
      Uri myUrl = webBrowser.Url;  //This is how I have been trying to get it.
  </code></pre>
  
  <p>So when I load my webBrowser control I send it to <code>http://www.mysite.com/startpage.html</code>. It does a javascript redirect to <code>http://www.mynewurl.com</code>.  I want to somehow capture that url in my c# code.</p>
  
  <p>Any ideas on how I can achieve this?</p>