在当前的WebView打开弹出式/外部站点链接 [英] Open pop up/external site link in current webview

查看:640
本文介绍了在当前的WebView打开弹出式/外部站点链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个web视图,它首先加载一个Twitter页面(例如, 非霍奇金淋巴瘤, http://twitter.com/nhl ) 正如你所看到的,你可以找到鸣叫的非霍奇金淋巴瘤和非霍奇金淋巴瘤的每个鸣叫有 另一个链接,用户点击,例如bit.ly/ujcNZo

I am currently writing a webview, it first loads a twitter page (say, NHL, http://twitter.com/nhl) as you can see, you can find the tweet for NHL, and each NHL tweet has another link for user to click, e.g. bit.ly/ujcNZo

在我的web视图,如果我点击该链接(即bit.ly/ujcNZo),我的web视图, 1秒钟后,没有在一个白色显示任何东西,但一个Twitter图标 背景颜色,它应该加载的内容,但事实并非如此。

in my webview, if i click that link (i.e. bit.ly/ujcNZo), my webview, after 1 second, doesn't display anything but a twitter icon on a white color background, it should load the content but it didn't.

在调查了一段时间,我认为它是与事实 在鸣叫(即bit.ly/ujcNZo)的链接实际上是打开的 在单独的窗口(弹出?)链路,而不是在当前页面所在的 链接贴出来,我通过进入NHL的Twitter页面上的验证了这一点 浏览器在我的笔记本电脑。

after some time of investigation, i think it has to do with the fact that the link in the tweet (i.e. bit.ly/ujcNZo) actually opens the link in a separate window (pop up?) and not the current page where the link is posted, i verified this by going to NHL's twitter page on a browser in my laptop.

我的问题是, 1.有没有办法,我可以加载外部链接的内容(bit.ly/ ujcNZo,如)在我目前的WebView?

My Question is, 1. is there a way i can load the content of the external link (bit.ly/ ujcNZo, for instance) in my current webview?

推荐答案

您可以通过WebViewClient类控制这一点。简单地扩展它,并覆盖默认实现,以获得所需的配置,然后将其设置为客户端您当前的WebView。

You can control this through the WebViewClient class. Simply extend it and override the default implementation to get the desired configuration then set it as the client for your current webview.

活动

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

            // set the webViewClient to a new instance of your custom WebViewClient

    webview.setWebViewClient(new WebActivityClient( this ));

}

自定义客户端

/** WebViewClient class for WebView in WebActivity */
private class WebActivityClient extends WebViewClient {

    public static final String TAG = "WebActivityClient";
    private Context context;

    /** Constructor used to grab the context */
    public WebActivityClient( Context context ) {
        this.context = context;
    }

    /** Override to load every link within the page inside this webview instead of using
     * android's default application
     * #7 http://developer.android.com/resources/tutorials/views/hello-webview.html */
    @Override
    public boolean shouldOverrideUrlLoading( WebView view, String url ) {
        view.loadUrl(url);
        return true;
    }

}

希望这有助于!

Hope this helps!

这篇关于在当前的WebView打开弹出式/外部站点链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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