网页浏览内部链接 [英] Webview internal links

查看:29
本文介绍了网页浏览内部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页视图,可以加载链接.我得到了一些 Url ,其中还包含其他 Url .我想知道是否有可能,当用户单击 webview 中的 url 时,该 url 将加载到另一个浏览器中,而不是在 webview 中?

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 , that url to be loaded in another browser , not inside the webview??

推荐答案

使用以下代码,如果链接在您的网站中,它将在 webview 中打开,否则将打开一个新浏览器:

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(new WebViewClient(){
public boolean shouldOverrideUrlLoading(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 page
        return false;
    }
    // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
    return true;
}});

更多信息:http://developer.android.com/guide/webapps/webview.html#AddingWebView

这篇关于网页浏览内部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆