shouldOverrideUrlLoading gets called ONLY for SOME

2019-06-24 11:28发布

问题:

I'm using the method shouldOverrideUrlLoading for an app that is personalised for multiple clients. Each client has it's own webpage that wants to be loaded into the webview. My problem is this: the app works perfect for client A and his webpage, but doesn't for client's B webpage (which isn't related with client A in any way). The difference, as I've tested, is that in client's B situation for the links that are accessed within the loaded content into the webview, shoulOverrideUrlLoading isn't working (NEVER gets called) and for client's A webpage works perfectly. Another thing is that client's B webpage doesn't work only on some Android versions, like 2.1 or 2.3.6 but it works fine on 2.3.3, 2.3.5, 4.0.2 or 4.0.3.

So this is kinda odd. If you happen to know anything, please help! Thanks!:)

EDIT: I noticed that shouldOverrideLoading isn't called when the webpage does NOT load the requested link through javascript and it works when javascript isn't used!!! but when I set webview.setJavaScriptEnabled(false) it works!!! I really need javascript to be enabled for my app cause the webpages usually use javascript for other things besides loading so I cannot disable it just because shouldOverrideUrlLoading doesn't get called!

EDIT 2: To be more exact:

This one works and shouldOverrideUrlLoading gets called:

<p onclick="location.href='linkHere'">
        NewLink
        <span class="icon-arrow"></span>
</p>

This one does NOT work and shouldOverrideUrlLoading does NOT get called:

<a class="link-inherit" href="linkHere">
        NewLink
        <span class="icon-arrow"></span>
</a>

回答1:

Solution for shouldOverrideUrlLoading not called

public void onPageStarted(WebView view, String url, Bitmap favicon) {

        if (url.contains("success")) {
            Intent intent = new Intent(WebviewActivity.this, OrderConfirmActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        } else {
            super.onPageStarted(view, url, favicon);
        }
    }