C#geckoFX(AutoJSContext不工作)

时间:2014-08-09 02:51:25

标签: c# winforms forms window geckofx

我是新来的,希望在C#中使用geckoFX提供一些帮助

所以我刚刚下载了geckoFX并做了以下工作。

1.Downloaded:geckofx.dll

2.downloaded:xulrunner

我成功添加了geckofx浏览器并且工作正常但是当我尝试运行此代码以向页面添加javascript时出现错误。

我得到的错误是:skybound.geckoFX.AutoJSContext不包含evaluate script和jscontext的定义。

我也不知道这是否有帮助,但AutoJSContext和EvaluateScript没有高亮显示。

这是我的代码

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Skybound.Gecko;


namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        Skybound.Gecko.Xpcom.Initialize(@"C:\Program Files\xulrunner");
    }

    private void geckoWebBrowser1_DocumentCompleted(object sender, EventArgs e)
    {
        string outString = "";
        using (AutoJSContext java = new AutoJSContext(geckoWebBrowser1.Window.JSContext))
        {
            java.EvaluateScript(@"window.alert('alert')", out outString);
        }


    }
}

先谢谢。

1 个答案:

答案 0 :(得分:2)

您应该像这样调用EvaluateScript:

java.EvaluateScript(@"window.alert('alert')", (nsISupports)geckoWebBrowser1.Window.DomWindow, out result);