Android的 - 在web视图打开目标_blank环节与外部浏览器 [英] Android - Open target _blank links in WebView with external browser

查看:171
本文介绍了Android的 - 在web视图打开目标_blank环节与外部浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建一个的WebView 它显示一个网站。该网站包含无目标链路=_空白属性以及一些吧。

I build a WebView which displays a website. The website contains links without a target="_blank" attribute and some with it.

我需要打开与目标在外部标准的设备浏览器定义和那些链接没有它的WebView里面。

I need to open the links with target defined in the external standard device browser and the ones without it inside the WebView.

我使用了一个 WebViewClient 键,我想围绕这个功能,但还是我所有的链接都在的WebView中打开

I'm using a WebViewClient and I tried around with this function but still all my links are opened within the WebView:

选择1:

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

    return super.shouldOverrideUrlLoading(view, url);        
}

选择2:

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

    view.loadUrl(url);
    return true;        
}

有谁知道我可以从外部打开空白的链接?

Does anybody know how I can open blank-links externally?

谢谢!

PS:为了避免missunderstandings:我不能使用这种方法因为只有这样,我知道的链接应该是打开externallly是目标属性。

PS: To avoid missunderstandings: I can't use this approach because the only way I know the link should be opened externallly is the target attribute.

推荐答案

接受的答案没有显示所需的确切code。访问上面的链接之后,我来到了这个code,并希望这会有所帮助。

The accepted answer did not show the exact code required. After visiting the above links, I come up with this code and hope this helps.

wv.getSettings().setSupportMultipleWindows(true);
wv.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg)
    {
        WebView.HitTestResult result = view.getHitTestResult();
        String data = result.getExtra();
        Context context = view.getContext();
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
        context.startActivity(browserIntent);
        return false;
    }
});

这篇关于Android的 - 在web视图打开目标_blank环节与外部浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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