【问题标题】:Is there a way to get cross domain of web page inside of Iframe in webbrowser control?有没有办法在 webbrowser 控件中获取 iframe 内的网页跨域?
【发布时间】:2011-06-25 07:02:12
【问题描述】:

我一直在寻找至少知道网页中 iframe(具有跨域)的域的方法,使用 .NET WebBrowser 控件。

我正在使用 .NET 2.0 Visual Studio 2005 C#

例如在 webbrowser 控件中,它的网页带有不同域的 iframe。

我想获得值“www.google.com”

http://localhost/index.html

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

由于根据 MSDN 的跨域脚本,我尝试获取域并获取 UnauthorizedAccessException

  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");
      }
    }
  }

但看起来我什至无法访问该域。

我也尝试过 Url frames[i].Url 仍然是同样的异常。

这是否意味着除了 iframe 之外,我无法从 iframe 中获取任何信息?有没有办法在不抛出异常的情况下检测 iframe 是否具有不同的域?

【问题讨论】:

  • hmm 看起来不像,访问任何方法,HtmlDocument 下面的属性都会抛出 UnauthorizedAccessException。

标签: .net webbrowser-control cross-domain


【解决方案1】:

这是浏览器的一项安全功能,可阻止人们上当受骗。否则,您可以将他们最喜欢的银行网站嵌入 iFrame 并从中提取数据。

【讨论】:

    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多