简体   繁体   中英

Is there a way to get cross domain of web page inside of Iframe in webbrowser control?

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.

I'm using .NET 2.0 Visual Studio 2005 C#

For instance in the webbrowser control, it has web page with iframe with different domain.

I want to get the value "www.google.com"

http://localhost/index.html

<html>
  <head></head>
  <body>
    <iframe src="http://www.google.com/foobar"></iframe>  
  </body>
</html>

I tried to get domain and getting UnauthorizedAccessException due to Cross Domain Scripting according to MSDN.

  HtmlWindowCollection frames = webBrowser1.Document.Window.Frames;
  if (frames.Count > 0)
  {
    for (int i = 0, j = frames.Count; i < 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");
      }
    }
  }

But looks like I can't even get access to the domain.

I've tried Url too frames[i].Url and still same exception.

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?

This is a security feature of browsers to stop people being scammed. Otherwise you could embed their favourite bank website in an iFrame and extract data from it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM