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;
I have solved the problem by using:
Microsoft.mshtml;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With