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:
Add a project reference to Microsoft.mshtml
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.