C # OpenWebKitSharp.NET 4 - How to call javascript

I am trying to call javascript using OpenWebKitSharp from WinForms with .NET 4

Here is the code I'm trying to use.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WebKit;
using WebKit.Interop;
using WebKit.JSCore;
using webkitForm.Properties;

namespace webkitForm
{
    public partial class Form1 : Form
    {

        WebKitBrowser webKitSharpBrowser = new WebKitBrowser();

        public Form1()
        {
            InitializeComponent();

            this.Controls.Add(webKitSharpBrowser);
            webKitSharpBrowser.Width = 600;
            webKitSharpBrowser.Height = 400;


        }


        private void button1_Click(object sender, EventArgs e)
        {
            webKitSharpBrowser.Preferences.AllowPlugins = true;
            webKitSharpBrowser.UseJavaScript = true;
            webKitSharpBrowser.Navigate("http://sandbox.icontact.com");


            webKitSharpBrowser.GetScriptManager.EvaluateScript("alert('An alert from C#!');"); //Call javascript?

        }

    }
}

I can't run javascript for anything ... there must be something that I don't see.

Thanks in advance.

+5
source share
1 answer

Well, it looks like this cannot be done the way you want:

if you are using .NET 4, a function call is possible with:

<webkitbrowser>.GetScriptManager.CallFunction("name", new Object[] { arg1, arg2, ...}); 

If you want to use .NET 2, you can use:

<webkitbrowser>.StringByEvaluatingJavaScriptFromString("name(arguments)")

- Open problems with Webkit Sharp

+3
source

All Articles