我正在尝试使用awesomium来创建一个基本的应用程序,我正在测试js <----> c#通信,但这似乎不能正常工作......我创建了一个本地html并打开它..这么好..但是,当我尝试调用js没有任何事情发生,没有错误,没有错误,没有,只是这不会调用js ..
我的基本js代码是:
var base = {
newItem : function(item){
$("#botones").append('<div class="botonMenu">' + item + '</div>');
},
other : function(){
alert("hi!!");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在firebug中测试这个,显然我可以很好地调用我的功能并创建项目或警告框...
now..my c#代码就是这个
//I've wrote this code inside the winForms sample..but change the code for load
//my local file and call js....
WebCore.BaseDirectory = @"C:\Documents and Settings\ME\dummytests\codes\views";
webView.LoadFile("base.html");
JSValue param1 = new JSValue("nameItem");
webView.CallJavascriptFunction("base", "other");
webView.CallJavascriptFunction("base","newItem", param1);
webView.Focus();
Run Code Online (Sandbox Code Playgroud)
这个文件负载很好,但是js通信不起作用,非常感谢,我希望可以帮助我...这个awesomium真的很棒
问题是您试图在页面完成加载之前调用页面上的 Javascript。如果等到加载完成后,您应该会看到它正确执行。
webView.LoadCompleted += ExecuteJavascript;
WebCore.BaseDirectory = @"C:\Documents and Settings\ME\dummytests\codes\views";
webView.LoadFile("base.html");
Run Code Online (Sandbox Code Playgroud)
...
private void ExecuteJavascript(object sender, EventArgs eventArgs)
{
JSValue param1 = new JSValue("nameItem");
webView.CallJavascriptFunction("base", "other");
webView.CallJavascriptFunction("base", "newItem", param1);
webView.Focus();
}
Run Code Online (Sandbox Code Playgroud)