简体   繁体   中英

WPF WebBrowser HTMLDocument

I'm trying to inject some javascript code to prevent javascript error popup, but I cannot find HTMLDocument and IHTMLScriptElement in WPF:

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);
    }
}

To clarify, Microsoft.mshtml isn't the 'using', it's a reference.

Full solution:

  1. Add a project reference to Microsoft.mshtml

  2. Add using mshtml;

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

Microsoft.mshtml;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM