有没有办法像使用 shouldOverrideUrlLoading()
的普通 hrefs 一样拦截 WebView
中的 javascript 触发的 URL?
最佳答案
onLoadResource()
在调用任何资源时调用,包括 JavaScript。虽然目的与 shouldOverrideUrlLoading()
有点不同.
webControls.setWebViewClient(new WebViewClient() {
//Notify the host application that the WebView will load
//the resource specified by the given url.
@Override
public void onLoadResource (WebView view, String url) {
super.onLoadResource(view, url);
Log.v(TAG, "onLoadResource("+url+");");
}
//Give the host application a chance to take over the
//control when a new url is about to be loaded in the
//current WebView.
@Override
public void shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
Log.v(TAG, "shouldOverrideUrlLoading("+url+");");
}
}
关于javascript - 有没有办法在 webview 中拦截 javascript 触发的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3572674/