title: Is there a way to get cross domain of web page inside of Iframe in webbrowser control?
body: <p>I've been searching around the way to at least know what domain the iframe (with cross-domain) in the web page has, using .NET WebBrowser control.</p>
  
  <p>I'm using .NET 2.0 Visual Studio 2005 C#</p>
  
  <p>For instance in the webbrowser control, it has web page with iframe with different domain.</p>
  
  <p>I want to get the value "www.google.com"</p>
  
  <p><strong>http://localhost/index.html</strong></p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;&lt;/head&gt;
    &lt;body&gt;
      &lt;iframe src="http://www.google.com/foobar"&gt;&lt;/iframe&gt;  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I tried to get domain and getting <code>UnauthorizedAccessException</code> due to Cross Domain Scripting according to MSDN.</p>
  
  <pre><code>  HtmlWindowCollection frames = webBrowser1.Document.Window.Frames;
    if (frames.Count &gt; 0)
    {
      for (int i = 0, j = frames.Count; i &lt; j; i++)
      {                        
        //if the iframe in the page has different domain
        if (frames[i].Document.Domain != this.webBrowser1.Document.Domain)
        {
           MessageBox.Show("iframe has different domain");
        }
      }
    }
  </code></pre>
  
  <p>But looks like I can't even get access to the domain.</p>
  
  <p>I've tried Url too <code>frames[i].Url</code> and still same exception.</p>
  
  <p>Does this mean I can't really get any information from the Iframe other than it is an iframe? Is there a way to detect if an iframe has different domain without throwing exception?</p>