WPF WebBrowser控件解析 HTML

WPF WebBrowser控件解析 HTML

xml 复制代码
Window里面的AllowsTransparency属性不要加
xml 复制代码
<WebBrowser x:Name="webBrowser"  />
csharp 复制代码
public void InitWeb()
{
   string htmlString = @"<html>
    <head>
        <title>this is a test</title>
        <script type ='text/javascript'>
            function Hello()
            {
                window.external.Hello('hello test'); // 传递事件
            }
        </script>
    </head>
    <body>
        <button onclick = 'Hello()'>
            hello test
        </button>
    </body>
</html> ";
            webBrowser.NavigateToString(htmlString);


            ObjectForScriptingHelper helper = new ObjectForScriptingHelper(this);
            webBrowser.ObjectForScripting = helper;
}
csharp 复制代码
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]//将该类设置为com可访问
    public class ObjectForScriptingHelper
    {
        signature mainWindow;

        public ObjectForScriptingHelper(signature main) // 注意signature 要写成你自己项目中的对象名
        {
            mainWindow = main;
        }

        //这个方法就是网页上要访问的方法
        public void Hello(string cmd)
        {
        }
    }
相关推荐
tiandyoin7 小时前
给 MHTML 添加滚动条.mhtml
前端·chrome·html·mhtml
Never_Satisfied12 小时前
在JavaScript / HTML中,HTML元素自定义属性使用指南
开发语言·javascript·html
码农水水13 小时前
得物Java面试被问:大规模数据的分布式排序和聚合
java·开发语言·spring boot·分布式·面试·php·wpf
_OP_CHEN13 小时前
【前端开发之HTML】(二)HTML 常见标签(上):从入门到实战,搞定网页基础排版!
前端·css·html·前端开发·网页开发·html标签
♩♬♪.14 小时前
HTML学校官网静态页面
前端·css·html
Never_Satisfied14 小时前
在JavaScript / HTML中,cloneNode()方法详细指南
开发语言·javascript·html
37方寸15 小时前
前端基础知识(HTML、CSS)
前端·css·html
时光慢煮15 小时前
行走在多端之间:基于 Flutter × OpenHarmony 的旅行记录应用实践 —— 旅行详情查看模块解析
flutter·华为·开源·wpf·openharmony
xiaobaishuoAI1 天前
分布式事务实战(Seata 版):解决分布式系统数据一致性问题(含代码教学)
大数据·人工智能·分布式·深度学习·wpf·geo
小北方城市网1 天前
微服务注册中心与配置中心实战(Nacos 版):实现服务治理与配置统一
人工智能·后端·安全·职场和发展·wpf·restful