WPF 网页浏览器 HTML 文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12834742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF WebBrowser HTMLDocument
提问by Alvin
I'm trying to inject some javascript code to prevent javascript error popup, but I cannot find HTMLDocumentand IHTMLScriptElementin WPF:
我正在尝试注入一些 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);
}
}
回答by HughHughTeotl
To clarify, Microsoft.mshtmlisn't the 'using', it's a reference.
澄清Microsoft.mshtml一下,不是“使用”,而是参考。
Full solution:
完整解决方案:
Add a project reference to
Microsoft.mshtmlAdd
using mshtml;
添加项目引用
Microsoft.mshtml添加
using mshtml;
回答by Alvin
I have solved the problem by using:
我已经通过使用解决了这个问题:
Microsoft.mshtml;

