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)
        {
        }
    }
相关推荐
三千道应用题5 小时前
WPF学习笔记(13)列表框控件ListBox与数据模板
wpf
veminhe9 天前
HTML5 浏览器支持
前端·html·html5
甄天9 天前
WPF中MVVM和MVVMLight模式
c#·wpf·visual studio
訾博ZiBo9 天前
开源分享:我开发了一个智能文本提取浏览器插件,彻底解决复制粘贴的烦恼
前端·react.js·html
A5资源网9 天前
为WordPress 网站创建一个纯文本网站地图(Sitemap)
前端·数据仓库·html·php
伍哥的传说10 天前
Node.js爬虫 CheerioJS ‌轻量级解析、操作和渲染HTML及XML文档
爬虫·node.js·html
gavin_gxh10 天前
倒计时 效果
前端·css·html
白话11 天前
Vue2批量生成二维码并下载
javascript·html
颜漠笑年11 天前
看看DeepSeek是如何实现前端日历组件的?
前端·html·代码规范
veminhe11 天前
HTML5简介
前端·html·html5