从 WebBrowser 控件中删除 Javascript/ChildElement

发布于 2024-08-05 11:10:21 字数 437 浏览 2 评论 0原文

我正在使用下面的代码注入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-08-12 11:10:21

我认为显式删除元素是不可能的(没有检查 IHTML 接口)。
但这也可以通过两种不同的方式完成:

  1. element.OutherHtml = string.empty; =>删除整个元素,但并不总是有效
  2. 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:

  1. element.OutherHtml = string.empty; => removes the whole element but does not always work
  2. HtmlElement blankScript = _wb.Document.CreateElement("script");
    element = blankScript; => replaces your unwanted script with a blank one
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文