首页 > Windows开发 > 详细

winform中使用webBrowser时如何与JS交互

时间:2015-10-08 16:32:29      阅读:348      评论:0      收藏:0      [点我收藏+]

最近写一个GEPlugin项目,要用到geWebBrowser与JS进行交互。

这个geWebBrowser的事件

private void geWebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlElement script = geWebBrowser1.Document.CreateElement("script");
            script.SetAttribute("type","text/javascript");
            script.SetAttribute("text",@"function fun(){
                    alert(‘Hello‘);       
            }");
            HtmlElement head = geWebBrowser1.Document.Body.AppendChild(script);
        }

  调用:

 private void button3_Click(object sender, EventArgs e)
        {
            geWebBrowser1.Document.InvokeScript("fun");
            //geWebBrowser1.Document.InvokeScript();
        }

简单,粗暴,神奇的Hello就弹出来咯

 

技术分享

这个项目中貌似还用不到JS中调用C#,查找后貌似可以这样实现,参考以下地址

参考:http://www.cnblogs.com/long_/archive/2012/02/13/2349795.html

winform中使用webBrowser时如何与JS交互

原文:http://www.cnblogs.com/joeymary/p/4861093.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!