我从这个来源创建了一个 IE 扩展: 如何开始开发 Internet Explorer 扩展? 而且效果很好。但我想改变
int IOleCommandTarget.Exec(IntPtr pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
{
var form = new HighlighterOptionsForm();
form.InputText = TextToHighlight;
if (form.ShowDialog() != DialogResult.Cancel)
{
TextToHighlight = form.InputText;
SaveOptions();
}
return 0;
}
对此:
int IOleCommandTarget.Exec(IntPtr pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
{
HTMLDocument document = (HTMLDocument)browser.Document;
IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)
document.all.tags("head")).item(null, 0);
IHTMLScriptElement scriptObject =
(IHTMLScriptElement)document.createElement("script");
scriptObject.type = @"text/javascript";
var text = @"alert('hello') ";
scriptObject.text = "(function(){" + text + "})()";
((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptObject);
return 0;
}
但是当我构建它时,然后单击按钮。我没有给我一个警报信息。我只想注入一个脚本。任何想法或技巧......解决这个问题