[英]Remove Javascript/ChildElement from WebBrowser Control
I am using below code to inject javascript 我正在使用下面的代码来注入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 现在有人可以告诉我如何删除添加的孩子
I think explicit deleting of an element is not possible (did not check the IHTML interfaces on this). 我认为不可能显式删除元素(没有检查此的IHTML接口)。 But this can be done in 2 different ways too:
但这也可以通过两种不同的方式完成:
element.OutherHtml = string.empty;
=> removes the whole element but does not always work HtmlElement blankScript = _wb.Document.CreateElement("script");
element = blankScript;
=> replaces your unwanted script with a blank one
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.