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)
        {
        }
    }
相关推荐
荔枝一杯酸牛奶4 小时前
HTML 表单与表格布局实战:两个经典作业案例详解
前端·html
米奇妙妙wuu5 小时前
css实现文字和边框同样的渐变色效果
css·html·css3
十六年开源服务商14 小时前
WordPress在线聊天系统推荐
大数据·javascript·html
jzlhll12315 小时前
android经常用到的一个小工具颜色计算器
html
郭优秀的笔记15 小时前
html鼠标悬浮提示功能
android·javascript·html
执笔论英雄16 小时前
【大模型推理】VLLM 引擎使用
wpf·vllm
LateFrames16 小时前
动画性能比对:WPF / WinUI3 / WebView2
wpf·webview·用户体验·winui3
_OP_CHEN16 小时前
【前端开发之HTML】(三)HTML 常见标签(下):图文、链接与实战,解锁网页交互新姿势!
前端·html·交互·前端开发·网页开发·界面美化
lkbhua莱克瓦241 天前
JavaScript核心语法
开发语言·前端·javascript·笔记·html·ecmascript·javaweb
0思必得01 天前
[Web自动化] Selenium中Select元素操作方法
前端·python·selenium·自动化·html