1

我有一个 webview,它加载了一个不是我的应用程序的外部 javascript 移动应用程序,所以我无法操作它。

这个 javascript 应用程序的问题:它不断调用某个 url。在 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 毫秒自动发出一个请求。我想知道如何阻止页面这样做?

有什么建议吗?

4

1 回答 1

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;
    }

   ...
}
于 2013-10-28T22:12:01.100 回答