繁体   English   中英

是否有办法在webbrowser控件的iframe中获取网页的跨域?

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

我一直在使用.NET WebBrowser控件进行搜索,以至少了解iframe(具有跨域)在网页中的域。

我正在使用.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");
      }
    }
  }

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

我也尝试过网址frames[i].Url url frames[i].Url和仍然相同的异常。

这是否意味着除了iframe之外,我实际上无法从iframe获得任何信息? 有没有一种方法可以检测iframe是否具有其他域而不会引发异常?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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