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 :(