WPF WebBrowser HTMLDocument

Alv*_*vin 7 c# wpf

我试图注入一些JavaScript代码,以防止JavaScript错误弹出,但我无法找到HTMLDocumentIHTMLScriptElementWPF中:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

Hug*_*otl 18

澄清Microsoft.mshtml一下,不是'使用',它是一个参考.

完整解决方案

  1. 添加项目引用 Microsoft.mshtml

  2. using mshtml;


Alv*_*vin 6

我用以下方法解决了这个问题:

Microsoft.mshtml;
Run Code Online (Sandbox Code Playgroud)