How to call JavaScript from Mono#39;s WebKitSharp?(如何从 Mono 的 WebKitSharp 调用 JavaScript?)
问题描述
我尝试了这个代码.一切正常,但我找不到到达 DOM 或从中调用 JavaScript 的方法.任何想法如何做到这一点?这是使用 GTK# 和 WebKitSharp.
I tried this code. All works, but I can't find a way to reach the DOM or to call JavaScript from it. Any ideas how to do that? This is using GTK# and WebKitSharp.
我还需要得到结果.
推荐答案
webView.ExecuteScript("alert('An alert from C#!');");
会成功的.
返回结果是另一个挑战:WebKit.DOMDocument 未在 webkit-sharp 中实现,因此您无法访问 DOM.有一些解决方法,这是我们通常做的:
Getting the results back is another challange though: WebKit.DOMDocument is not implemented in webkit-sharp, so you can't access the DOM. There are a few workarounds, this is what we normally do:
- 在页面的某处有一个不可见的框架
- 通过
webView.MainFrame.FindFrame("framename")
为其获取 WebFrame - 在你的 JS 中将你的结果写到这个不可见框架的标题中
- 使用
myWebFrame.Title
从 C# 中读取它
- Have a invisible frame somwhere in your page
- Get the WebFrame for it via
webView.MainFrame.FindFrame("framename")
- in your JS write your result to the title of this invisible frame
- use
myWebFrame.Title
to read it from C#
这篇关于如何从 Mono 的 WebKitSharp 调用 JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Mono 的 WebKitSharp 调用 JavaScript?


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01