Skip to content Skip to sidebar Skip to footer

Webview Internal Links

I got a webview, that loads links. I got some Url , that they also contain other Url's inside it. I was wondering if it is possible ,when user click on an url inside webview , tha

Solution 1:

With the following code if the link is in you web site it will be opened inside the webview otherwise it will open a new browser:

webView.setWebViewClient(newWebViewClient(){
publicbooleanshouldOverrideUrlLoading(WebView view, String url) {
    if (Uri.parse(url).getHost().equals("www.example.com")) {
        // This is my web site, so do not override; let my WebView load the pagereturnfalse;
    }
    // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLsIntent intent = newIntent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
    returntrue;
}});

For more info: http://developer.android.com/guide/webapps/webview.html#AddingWebView

Post a Comment for "Webview Internal Links"