简体   繁体   中英

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!

您总是可以像这样调用javascript:

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

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')");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM