2011-06-25 20 views
1

我一直在搜索周圍的方式,至少知道什麼域的網頁iframe(與跨域),使用.NET WebBrowser控件。有沒有一種方法可以在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> 

我試圖讓域和獲得UnauthorizedAccessException由於交叉根據MSDN的域腳本。

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,但仍然是例外。

這是否意味着我無法從Iframe中獲取任何信息,而不是iframe?有沒有辦法檢測iframe是否有不同的域而不拋出異常?

+0

hmm看起來不像,訪問任何方法,HtmlDocument下面的屬性拋出UnauthorizedAccessException。 –

回答

1

這是瀏覽器的一項安全功能,可以阻止人們被騙。否則,您可以將他們最喜歡的銀行網站嵌入到iFrame中並從中提取數據。

相關問題