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)
        {
        }
    }
相关推荐
勇往直前plus3 小时前
前端三基石:从后端视角理解 HTML、CSS 与 JavaScript
前端·css·html
酉鬼女又兒6 小时前
零基础快速入门前端CSS Transform 与动画核心知识点及蓝桥杯 Web 应用开发考点解析(可用于备赛蓝桥杯Web应用开发)
开发语言·前端·css·职场和发展·蓝桥杯·html
白露与泡影9 小时前
Spring Cloud进阶--分布式权限校验OAuth2
分布式·spring cloud·wpf
sensen_kiss9 小时前
CAN302 电子商务技术 Pt.2 深入了解HTML和CSS
前端·css·学习·html
进击的雷神11 小时前
攻克HTML属性数据埋点与分页偏移陷阱:基于data-id属性提取的精准爬虫设计
前端·爬虫·html·spiderflow
枫叶丹412 小时前
【HarmonyOS 6.0】ArkData 分布式数据对象新特性:资产传输进度监听与接续传输能力深度解析
开发语言·分布式·华为·wpf·harmonyos
一念春风21 小时前
智能文字识别工具(AI)
开发语言·c#·wpf
故事不长丨1 天前
WPF MvvmLight 超详细使用教程
c#·wpf·mvvm·mvvmlight
天若有情6731 天前
前端HTML精讲03:页面性能优化+懒加载,搞定首屏加速
前端·性能优化·html
bjzhang751 天前
使用 HTML + JavaScript 实现 SQL 智能补全功能
javascript·html·sql智能补全