【问题标题】:How do you open a new link in the default browser rather than the webview with Javascript?如何在默认浏览器而不是使用 Javascript 的 webview 中打开新链接?
【发布时间】:2018-09-10 07:10:27
【问题描述】:

链接始终在 web 视图中打开,而不是在 android 的默认 Internet 浏览器中打开

我也在使用 iframe

【问题讨论】:

  • 附上你的代码。

标签: javascript android browser webview


【解决方案1】:

您可以在 WebView 中使用WebViewClient 处理重定向页面。

只需在您的WebView 中设置WebViewClient

mWebView.setWebViewClient(new MyWebViewClient());

WebViewClient 创建类,然后处理下一页。

private class MyWebViewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
             Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
             startActivity(browserIntent);
            Log.d("URL", " : " + url);
            return true;
        }
    }

【讨论】:

  • 感谢它像梦一样工作我也添加了新方法,因为 shouldOverrideUrlLoading(WebView view, String url) 已被弃用:public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
猜你喜欢
  • 1970-01-01
  • 2014-05-22
  • 2011-07-26
  • 1970-01-01
  • 1970-01-01
  • 2015-11-01
  • 2011-05-12
  • 1970-01-01
  • 2015-10-08
相关资源
最近更新 更多