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.Titleto read it from C#
这篇关于如何从 Mono 的 WebKitSharp 调用 JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Mono 的 WebKitSharp 调用 JavaScript?
基础教程推荐
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
