在我的WebView中,我设置了WebViewClient
,以便在页面加载时评估一些JavaScript
:
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
view.loadUrl("javascript:registerObjectDetailsCallback(" +
"function(details) {" +
"if (details.length == 1) {" +
"window.location.href = 'callback:' + escape(details[0]);" +
"} else if (details.length > 1) {" +
"alert('Error: callback set by registerObjectDetailsCallback was passed multiple selection');" +
"}" +
"}" +
");");
}
}
我在iOS中做了同样的事情,产生了预期的结果:
-(void) webViewDidFinishLoad:(UIWebView *)webView {
[serverWebView stringByEvaluatingJavaScriptFromString:
[NSString stringWithFormat:@"registerObjectDetailsCallback("
"function(details) {"
"if (details.length == 1) {"
"window.location.href = 'callback:' + escape(details[0]);"
"} else if (details.length > 1) {"
"alert('Error: callback set by registerObjectDetailsCallback was passed multiple selection');"
"}"
"})"]];
}
但是在Android中没有快乐。有任何想法吗?我是在错误的时间打电话吗?我应该使用WebChromeClient
吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
这里的问题是webapp和应用程序之间的竞争条件。方法运作正常。