【问题标题】:webview with iframe - back button goes back inside the iframe带有 iframe 的 webview - 后退按钮返回到 iframe 内
【发布时间】:2018-11-01 10:24:47
【问题描述】:

我有一个 android 项目,它只显示一个 web 视图。 我使用此功能通过设备的返回按钮转到上一页:

 @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                webView = findViewById(R.id.webView);                  

                if (webView.canGoBack()) {
                    webView.goBack();
                    return true;
                } else {
                   // alert dialog...
        }

    }
    return super.onKeyDown(keyCode, event);
}

这个功能是通过js在web视图中返回上一页的:

goBack()
{
history.go(-1);
}

在这两个函数中,如果页面包含 iframe,则 iframe 内的页面返回,而不是父页面。

如何让父页面返回而不是 iframe 内的页面在单击返回按钮时返回?

谢谢!

【问题讨论】:

    标签: android iframe android-webview


    【解决方案1】:

    这样试试

    goBack() {
    
            if(webView.canGoBack()) {
                webView.goBack();
            } else {
                finish()
            }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多