除了InvokeScript之外,Windows Phone 8中是否有类似于InvokeScriptAsync的函数
本文关键字:是否 类似于 InvokeScriptAsync 函数 之外 InvokeScript Windows Phone 除了 | 更新日期: 2023-09-27 18:23:49
根据我的代码执行,它是同步的,即。。我的JS Invokescript()函数等待其他正在执行的JS函数完成。因此,我需要为javascript异步执行InvokeScript函数。
请检查以下代码。
从JS文件调用函数
Bridge_Windows.netStatus = function() {
Bridge_Windows.result = null;
window.external.notify("function=netStatus&callback=" + function (response) {
Bridge_Windows.result = response;
});
while (Bridge_Windows.result == null) {
Bridge_Windows.timer = setInterval(function () {
clearInterval(Bridge_Windows.timer);
Bridge_Windows.timer = null;
}, 50);
}
return Bridge_Windows.result;
};
XAML文件
<phone:WebBrowser x:Name="orderWebView" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="480" Height="768" IsScriptEnabled="True" ScriptNotify="orderPageScriptNotify" IsGeolocationEnabled="True" Foreground="{x:Null}"/>
CS文件
private void orderPageScriptNotify(object sender, NotifyEventArgs e)
{
string responseJsNotify = null;
try
{
string []aa = e.Value.Split('&');
string[] bb = aa[0].Split('=');
responseJsNotify = jsNativeMethodCall(bb[1]);
MessageBox.Show(responseJsNotify);
string[] args = { "var "+aa[1]+";callback("+responseJsNotify.ToLower()+");" };
orderWebView.InvokeScript("eval", args);
}
catch(Exception ee) {
MessageBox.Show(e.Value);
}
}
请帮助我制作
orderWebView.InvokeScript("eval",args)作为异步调用?
根据文档,您还可以使用InvokeScriptAsync。文件:http://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.webview.aspx
此外,您还可以将调用封装在settimeout javascript调用中,然后在javascript框架中异步执行该调用。下面的示例使用0秒的延迟,这将立即(但异步)启动它。
setTimeout((function() {<do whatever you wanted to do>})(), 0);