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?
基础教程推荐
- C# 9 新特性——record的相关总结 2023-04-03
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 如果条件可以为空 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
