我有一个webview,它会加载一个不是我应用的外部javascript移动应用,所以我无法操纵它。
这个javascript应用程序的问题:它连续调用某个网址。 在WebViewClient.shouldInterceptRequest方法中,我记录了被调用的url。 这是输出:
10-28 21:40:38.701: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996438694&_=1382996438703
10-28 21:40:40.770: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996440763&_=1382996440775
10-28 21:40:42.880: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996442873&_=1382996442880
10-28 21:40:44.940: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996444934&_=1382996444942
10-28 21:40:47.000: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996446993&_=1382996447001
10-28 21:40:49.070: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996449044&_=1382996449053
10-28 21:40:51.120: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996451114&_=1382996451125
10-28 21:40:53.180: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996453166&_=1382996453180
10-28 21:40:55.240: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996455237&_=1382996455244
10-28 21:40:57.710: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996457295&_=1382996457714
10-28 21:40:59.770: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996459766&_=1382996459773
10-28 21:41:01.822: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996461813&_=1382996461820
10-28 21:41:03.871: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996463864&_=1382996463871
10-28 21:41:05.920: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996465914&_=1382996465921
所以你可以看到。每50至60毫秒自动生成一个请求。我想知道如何阻止页面这样做?
有任何建议吗?
答案 0 :(得分:0)
尝试覆盖shouldOverrideUrlLoading
,如下所示:
public class MyWebClient extends WebViewClient {
...
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.startsWith("https://m.tipico.com/ajax/login/register")) {
return true;
}
return false;
}
...
}