【问题标题】:How to redirect to a specific page in webview when back button pressed?按下后退按钮时如何重定向到webview中的特定页面?
【发布时间】:2017-05-13 13:51:50
【问题描述】:

我有一个工作代码,它重定向到 webview 历史中的上一页。

我想将其重定向到特定页面(example.com)。

谁能告诉我该怎么做?

@Override
    public void onBackPressed() {
        if (mWebview.canGoBack()) {
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
                String currenturl = sharedPreferences.getString("currentpage", null);

                if (currenturl.contains("http://google.com/")){
                    mWebview.requestFocus();
                    mWebview.goBack();
//    mWebview.loadUrl("http://example.com");
                }
        }
    }

【问题讨论】:

  • 目前的结果是什么?
  • 带你到上一页

标签: android webview


【解决方案1】:

经过反复试验,找到了它

删除

if (mWebview.canGoBack()){

替换

mWebview.goBack();

mWebview.loadUrl("http://example.com");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多