【发布时间】: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