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?


基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01