2011-05-23 69 views
0

我正在使用C# .NET Framework 2.0来创建应用程序,可以用户在WebBrowser控件中选取DOM元素的点击部分。单击时可以在iFrame内部拾取DOM元素吗?

到目前为止,我可以在WebBrowser控件中的HTML中选择html标签及其属性。

//adding event when user mouse down or focus out 
webBrowser1.Document.MouseDown += new HtmlElementEventHandler(myMouseDown); 

而这些事件将输出DOM信息列表框等

private void myMouseDown(object sender, HtmlElementEventArgs e) 
{ 
    HtmlElement tag = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition); 

    txtRecord.Items.Add("TagName=" + tag.TagName); 
    txtRecord.Items.Add("id=" + tag.GetAttribute("id")); 
    txtRecord.Items.Add("name=" + tag.GetAttribute("name")); 
    txtRecord.Items.Add("type=" + tag.GetAttribute("type")); 
    txtRecord.Items.Add("value=" + tag.GetAttribute("value")); 
    txtRecord.Items.Add("class=" + tag.GetAttribute("class")); 
    txtRecord.Items.Add("inner text=" + tag.InnerText); 

} 

但随后发生的事件鼠标按下不工作的iFrame。

当我点击iFrame内部时,它不会吐出DOM信息。

是否有可能通过用户点击iFrame中的该点来拾取DOM信息?

更新:

找到HtmlWindow对象并应用相同的事件逻辑。

HtmlWindow iFrame; 
iFrame = webBrowser1.Document.Window.Frames[0]; 
iFrame.Document.MouseDown += new HtmlElementEventHandler(myMouseDown); 

但随后的最后一行抛出UnauthorizedAccessException :(

回答

0

我发现了,为什么我得到UnauthorizedAccessException。这是因为我的主网​​页是http://localhost/index.html而IFRAME SRC是违反交叉框架脚本根据安全

http://msdn.microsoft.com/en-us/library/ms171715.aspx 
http://msdn.microsoft.com/en-us/library/ms533028.aspx 

我已经改变IFRAME SRC使用相同的域,http://localhost/secondPage.html

然后开始工作!

相关问题