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)
        {
        }
    }
相关推荐
Xin_ye1008615 小时前
第三章:内存泄漏的常见“案发现场”
c#·wpf
blns_yxl18 小时前
购物车(HTML+JS+CSS)
html
blns_yxl20 小时前
正则驱动实时表单验证(HTML+CSS+JS+正则)
javascript·css·html
心平气和量大福大20 小时前
C#-WPF-UserControl-生命周期(加载 退出)
开发语言·c#·wpf
大白要努力!1 天前
纯前端实现 PDF 加水印工具 —— 零后端、支持中文、实时预览
前端·pdf·html
蜡台1 天前
使用 uni-popup 实现数据选择器Data-Picker
前端·javascript·html·uniapp·uni-popup·data-picker
blns_yxl1 天前
Promise封装Fetch + 重试机制(HTML+JS)
前端·javascript·html
czhc11400756631 天前
7.23:Claude code:注册->封表
wpf
心平气和量大福大2 天前
C#-WPF-控件-TextBox 数据绑定
开发语言·c#·wpf
杨超越luckly2 天前
Agent应用指南:13年与13线——武汉地铁进化史
数据分析·html·agent·可视化·地铁客流