[英]Is there a way to get cross domain of web page inside of Iframe in 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. 我一直在使用.NET WebBrowser控件进行搜索,以至少了解iframe(具有跨域)在网页中的域。
I'm using .NET 2.0 Visual Studio 2005 C# 我正在使用.NET 2.0 Visual Studio 2005 C#
For instance in the webbrowser control, it has web page with iframe with different domain. 例如在webbrowser控件中,它具有带有iframe且具有不同域的网页。
I want to get the value "www.google.com" 我想获取值“ www.google.com”
http://localhost/index.html http://localhost/index.html
<html>
<head></head>
<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. 根据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");
}
}
}
But looks like I can't even get access to the domain. 但是看起来我什至无法访问该域。
I've tried Url too frames[i].Url
and still same exception. 我也尝试过网址
frames[i].Url
url frames[i].Url
和仍然相同的异常。
Does this mean I can't really get any information from the Iframe other than it is an iframe? 这是否意味着除了iframe之外,我实际上无法从iframe获得任何信息? Is there a way to detect if an iframe has different domain without throwing exception?
有没有一种方法可以检测iframe是否具有其他域而不会引发异常?
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.
否则,您可以将他们最喜欢的银行网站嵌入iFrame并从中提取数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.