我使用的是Gekofx浏览器,因为我的html文件无法使用默认的浏览器控件。我如何使用C#与Gekofx浏览器调用JavaScript函数
到目前为止,我正在使用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代码:'
的Hello World!
'有什么可以做的吗? –然后你用mybrowser.Navigate(“javascript:test('Test')”);? – Jordy
是的。没有反馈。但是它在将下面的代码部分放入我的'btn_test_Click'之后工作:'myBrowser.Navigate(path); MessageBox.Show(“Stop!”); myBrowser.Navigate(“javascript:test('Test')”);' 我不是没有为什么,但它的工作原理。你能解释我为什么? –