如何从 Mono 的 WebKitSharp 调用 JavaScript? [英] How to call JavaScript from Mono's WebKitSharp?

查看:21
本文介绍了如何从 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆