如何在WebBrowser控件中注入Javascript?

如何在WebBrowser控件中注入Javascript?,第1张

如何在WebBrowser控件注入Javascript?

由于某种原因,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");

该答案说明了如何将

IHTMLscriptElement
界面引入您的项目。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5441141.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存