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

查看:217
本文介绍了如何从Mono的WebKitSharp调用JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想 code。所有的作品,但我不能找到一个方法来达到DOM或从中调用JavaScript。任何想法如何做到这一点?这是使用GTK#和WebKitSharp。

编辑:另外,我需要得到的结果

解决方案

  webView.ExecuteScript(警报('从C#警报!'););
 

将这样的伎俩。

获取结果后面是另外一个challange虽然:WebKit.DOMDocument没有在WebKit的锐利实现的,所以你不能访问DOM。有几个解决方法,这就是我们通常做的:

  • 有一个无形的框架somwhere在你的页面
  • 获取WebFrame它通过 webView.MainFrame.FindFrame(framename)
  • 在JS写你的结果这种无形框架的标题
  • 使用 myWebFrame.Title 从C#
  • 阅读

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.

EDIT: Also I need to get the result.

解决方案

webView.ExecuteScript("alert('An alert from C#!');");

will do the trick.

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:

  • 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天全站免登陆