如何访问在 WinForms 中使用 webbrower 控件的 HTML 文档元素?
我正在使用 WinForms C# 3.5 WebBrowser
我试图访问以下 HTML 文档中的 head 元素:
this.webBrowserTest.DocumentText = @”<html>
<head>
<title>Test JavaScript WinForms</title>
<meta name="description" content="Test WinForms" />
</head>
<body></body>
</html>”
HtmlElementCollection headCollection = webBrowserTest.Document.GetElementsByTagName("HEAD");
HtmlElement head = headCollection[0]
headCollection[0]
被作为 null
传递有人知道出了什么问题吗?
谢谢
I'm using WinForms C# 3.5 WebBrowser
I’m trying to get access to the head element in the follow HTML Document:
this.webBrowserTest.DocumentText = @”<html>
<head>
<title>Test JavaScript WinForms</title>
<meta name="description" content="Test WinForms" />
</head>
<body></body>
</html>”
HtmlElementCollection headCollection = webBrowserTest.Document.GetElementsByTagName("HEAD");
HtmlElement head = headCollection[0]
headCollection[0]
is getting passed as null
Would any one have an idea whats wrong?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您获取
head
标记的代码看起来不错。在访问文档之前,请确保文档已完全加载。您可以通过执行以下操作来实现此目的:Your code to get the
head
tag looks fine. Make sure the document is fully loaded before accessing it. You can accomplish this by doing something like this:如果您为 head 元素提供 id="headid" 属性,则可以使用 webBrowserTest.Document.All["headid"]。
You can use webBrowserTest.Document.All["headid"], if you'll provide id="headid" attribute for head element.
你尝试过吗
Have you tried