问题描述
|
我一直在使用.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,由于跨域脚本,我试图获取域并获得ѭ1。
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\");
}
}
}
但是看起来我什至无法访问该域。
我也尝试过Urlframes[i].Url
,但还是一样。
这是否意味着除了iframe之外,我实际上无法从iframe获得任何信息?有没有一种方法可以检测iframe是否具有其他域而不会引发异常?
解决方法
这是浏览器的安全功能,可防止他人被骗。否则,您可以将他们最喜欢的银行网站嵌入iFrame中,并从中提取数据。