4

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>
philtz
  • 227
  • 6
  • 14
  • Maybe help http://stackoverflow.com/questions/6738328/shouldoverrideurlloading-in-webview-for-android-not-running – Vyacheslav Shylkin Mar 12 '12 at 15:48
  • yeah..I saw that post. Not exactly my case though. Thanks anyway :) – philtz Mar 13 '12 at 08:35
  • I am experiencing the same issue. Have you found a workaround for this yet? – Hamed May 06 '12 at 19:07
  • The problem seemed to be js function setTimeout(fn, millis). You have write a js function that overrides it and then recreate the behaviour of this function in your Android code (using JavascriptInterface) as it fits best for your app. It's a lot of work which depends of your app functionality, but it works. The code is too long to be posted here and also I am not allowed to make it public but the idea is overriding setTimeout then call a method from android code who sleeps the thread for how many millis were in the initial calling of the setTimeout in js and finally [to be continued...] – philtz May 15 '12 at 16:37
  • finally write another js function and call it from android. This second js function will just make the initial call using call() method for the function which was initially saved in a hash. This second js function needs to be called only if the type of the initial call is "function". If not you just call from android directly eval(\"" + fn + "\"); – philtz May 15 '12 at 16:40
  • pfff..i know it's complicated and i just read what i wrote and didn't understand much :)) but the idea is there and if you think for a while you can do it!:) sorry for not getting into more details! Maybe I'll write a tutorial someday when I'll have enough time for that! best of luck! – philtz May 15 '12 at 16:42

1 Answers1

3

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);
        }
    }
CRUSADER
  • 5,486
  • 3
  • 28
  • 64
Anh Duy
  • 1,145
  • 15
  • 25
  • 1
    ??? Does this work for anyone? I don't see how... Does Android attach a "success" suffix or what? I'm printing the url param in my onPageStarted and this is not case, at least for me. – acrespo Jan 29 '16 at 14:59