mariusz_witeczek
mariusz_witeczek

Reputation: 115

How can I invoke javascript functions with c# with Gekofx Browser

I am using the Gekofx browser because my html files don't work with the default webbrowser control.

So far I was using ObjectForScripting to call javascript code from my C# project. But I was not able to call anything with the Gekofx browser.

I just want to send some data to my html file and display it with the Gekofx browser. Is it possible at all?

For contemplation here is my code:

GeckoWebBrowser myBrowser;

    public Form1()
    {
        InitializeComponent();

        String path = @"C:\tools\xulrunner\xulrunner-sdk\bin";

        Console.WriteLine("Path: " + path);

        Skybound.Gecko.Xpcom.Initialize(path);

        myBrowser = new GeckoWebBrowser();
        myBrowser.Parent = this;
        myBrowser.Dock = DockStyle.Fill;
    }

    private void btn_go_Click(object sender, EventArgs e)
    {
        // like the normal browsers
        myBrowser.Navigate(tbx_link.Text);
    }

    private void btn_test_Click(object sender, EventArgs e)
    {
        // getting the link to my own html file
        String path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Webpage");
        path += "\\Webpage.html";myBrowser.Navigate(path);

    }

I hope you understand what I mean. Thank you!

Upvotes: 1

Views: 2005

Answers (2)

Thai Monk
Thai Monk

Reputation: 23

Building on @jordy's answer above, call:

mybrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");

prefferably in the Document complete event handler to allow for the page to first load.

 void myBrowser_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
    {
         myBrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");
    }

Upvotes: 0

Just J for now
Just J for now

Reputation: 1826

You can always invoke javascript like this:

mybrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");

Upvotes: 2

Related Questions