且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android:拦截来自 WebView 的 AJAX 调用

更新时间:2021-08-20 07:09:04

最后还是用了问题中描述的方法;

In the end I used the method described in the question anyway;

我拦截了一些特定的请求,例如:foo://bar/get/1?callback=foobar 然后解析 URL 并使用实际的数据.
回调函数是在 URL 的查询部分定义的,所以在上面的例子中就是: foobar();

I intercepted some specific requests like: foo://bar/get/1?callback=foobar then parsed the URL and called a javascript callback function with the actual data.
The callback function was defined in the query-part of the URL, so in the above example that would be: foobar();

调用该函数很简单,只需使用:yourWebView.loadUrl("javascript:foobar('somedata')");

Calling that function was easy, just use: yourWebView.loadUrl("javascript:foobar('somedata')");