0

I have a WebView that I'm trying to handle behavior for when #close is added to the end of a url.

The code below triggers for every load url that doesn't have #close appended to it. How do I handle for this?

WebViewClient wvc = new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView  view, String  url){
                return true;
            }

            @Override
            public void onLoadResource(WebView  view, String  url){
                if( url.equals("https:<coreofurl>/?#close") ){
                    // handle event - does not enter
                }
            }
        };

webView.setWebViewClient(wvc);

Edit: I've also tried the following with no luck.

WebChromeClient wcc = new WebChromeClient() {

            @Override
            public void onCloseWindow(WebView window) {
                // handle event - does not enter
            }
        };

        webView.setWebChromeClient(wcc);
rkeller
  • 69
  • 10

1 Answers1

0

This seems like a "how do I tell if my url ends with x" string question, so... try this

if (url.endsWith("#close")) {
    // close stuff here
}

(this would be implemented in your onLoadResource() method)

Tom
  • 6,946
  • 2
  • 47
  • 63
  • That's probably a better way of checking, but the onLoadResource() method isn't called at all, so at this point it didn't make a difference. Thanks for your reply though. – rkeller Nov 04 '14 at 20:06