开发者

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

开发者 https://www.devze.com 2023-03-15 03:21 出处:网络
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'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>
  <开发者_JS百科;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.

0

精彩评论

暂无评论...
验证码 换一张
取 消