[英]How to pass parameters by value to javascript functions from c# with Gekofx
[英]How can I invoke javascript functions with c# with Gekofx Browser
我使用的是Gekofx瀏覽器,因為我的html文件無法與默認的webbrowser控件一起使用。
到目前為止,我一直在使用ObjectForScripting從我的C#項目中調用javascript代碼。 但是我無法使用Gekofx瀏覽器調用任何東西。
我只想將一些數據發送到我的html文件中,並使用Gekofx瀏覽器顯示它。 有可能嗎?
考慮一下,這是我的代碼:
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);
}
我希望你明白我的意思。 謝謝!
您總是可以像這樣調用javascript:
mybrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");
以上述@jordy的答案為基礎,致電:
mybrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");
最好在Document complete事件處理程序中,以便首先加載頁面。
void myBrowser_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
{
myBrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.