从 WebBrowser 控件中删除 Javascript/ChildElement
我正在使用下面的代码注入 javascript
HtmlElement head = _wb.Document.GetElementsByTagName("head")[0]; HtmlElement scriptEl = _wb.Document.CreateElement("script"); mshtml.IHTMLScriptElement element = (mshtml.IHTMLScriptElement)scriptEl.DomElement; element.text = "function zoom(){document.body.style.zoom='150%';}"; head.AppendChild(scriptEl);
现在谁能告诉我如何删除添加的子项
I am using below code to inject javascript
HtmlElement head = _wb.Document.GetElementsByTagName("head")[0]; HtmlElement scriptEl = _wb.Document.CreateElement("script"); mshtml.IHTMLScriptElement element = (mshtml.IHTMLScriptElement)scriptEl.DomElement; element.text = "function zoom(){document.body.style.zoom='150%';}"; head.AppendChild(scriptEl);
Now can anyone tell me how to remove the added child
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为显式删除元素是不可能的(没有检查 IHTML 接口)。
但这也可以通过两种不同的方式完成:
element.OutherHtml = string.empty;
=>删除整个元素,但并不总是有效HtmlElement BlankScript = _wb.Document.CreateElement("script");
element = BlankScript;
=>;用空白脚本替换不需要的脚本I think explicit deleting of an element is not possible (did not check the IHTML interfaces on this).
But this can be done in 2 different ways too:
element.OutherHtml = string.empty;
=> removes the whole element but does not always workHtmlElement blankScript = _wb.Document.CreateElement("script");
element = blankScript;
=> replaces your unwanted script with a blank one