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)
        {
        }
    }
相关推荐
鬼手点金17 小时前
Scrapy 网络爬虫框架
爬虫·python·scrapy·ajax·html·json·requsts
鬼手点金1 天前
Scrapy + Playwright 完整示例(JS 动态渲染网页)
开发语言·javascript·爬虫·python·scrapy·html·json
—Qeyser1 天前
html 可视化海报模板编辑器
css·html·js
Polevne1 天前
WPF\MAUI\Avalonia Dispatcher
wpf
逝水无殇1 天前
HTML 文本格式化详解:掌握 <strong>、<em>、<mark>、<del> 等常用标签
前端·javascript·html
Ares-Wang1 天前
wpf 图表制作 LiveCharts
wpf
我命由我123451 天前
CesiumJS 笔记 - 获取容器中心点、Cartesian3 clone 方法、修改 Cartesian3 对象的高度
前端·javascript·css·前端框架·html·html5·js
A_nanda2 天前
c#WPF开发常见问题
开发语言·c#·wpf
jackyrongvip2 天前
开源一个可以把HTML敏感词替换的页面小工具
开源·html·敏感词·ai脱敏
@Mike@3 天前
HTML核心知识点笔记
前端·笔记·html