c# – WPF WebBrowser HTMLDocument
发布时间:2020-12-15 18:23:01 所属栏目:百科 来源:网络整理
导读:我正在尝试注入一些 javascript代码以防止javascript错误弹出,但我在WPF中找不到HTMLDocument和IHTMLScriptElement: var doc = browser.Document as HTMLDocument;if (doc != null){ //Create the sctipt element var scriptErrorSuppressed = (IHTMLScript
我正在尝试注入一些
javascript代码以防止javascript错误弹出,但我在WPF中找不到HTMLDocument和IHTMLScriptElement:
var doc = browser.Document as HTMLDocument; if (doc != null) { //Create the sctipt element var scriptErrorSuppressed = (IHTMLScriptElement)doc.createElement("SCRIPT"); scriptErrorSuppressed.type = "text/javascript"; scriptErrorSuppressed.text = m_disableScriptError; //Inject it to the head of the page IHTMLElementCollection nodes = doc.getElementsByTagName("head"); foreach (IHTMLElement elem in nodes) { var head = (HTMLHeadElement)elem; head.appendChild((IHTMLDOMNode)scriptErrorSuppressed); } } 解决方法
为了澄清,Microsoft.mshtml不是’使用’,它是一个参考.
完整解决方案 >将项目引用添加到Microsoft.mshtml>使用mshtml添加; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |