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)
        {
        }
    }
相关推荐
xy34531 小时前
Axure 9.0 动态面板基本操作
前端·ui·html·axure·原型·产品设计
qq_369173633 小时前
如何将 AI 生成的 HTML 网页发布成在线链接?不用自己搭建服务器
前端·人工智能·html·效率工具·html 发布
小凯在掘金4 小时前
Shadow DOM 和 Virtual DOM ?别再傻傻分不清
前端·html
预立科技6 小时前
CDN(内容分发网络)知识总结
网络·wpf·cdn
传人once1 天前
选择文件按钮样式如何美化
前端·html·css3·jquery·html5
Lucky_Turtle1 天前
【HTML】前端页面禁止缩放
前端·html
FuckPatience1 天前
WPF DataGrid 行根据某个属性循环变色动画
wpf
JYeontu2 天前
实现一个「曲线滑块验证」功能
前端·javascript·html
IMPYLH2 天前
HTML 的 <tr> 元素
前端·html
IMPYLH2 天前
HTML 的 <track> 元素
前端·html