由于某种原因,Richard的解决方案对我而言不起作用(insertAdjacentText失败,并带有异常)。但是,这似乎可行:
HtmlElement head = webBrowser1.document.GetElementsByTagName("head")[0];HtmlElement scriptEl = webBrowser1.document.CreateElement("script");IHTMLscriptElement element = (IHTMLscriptElement)scriptEl.DomElement;element.text = "function sayHello() { alert('hello') }";head.AppendChild(scriptEl);webBrowser1.document.Invokescript("sayHello");


