【问题标题】:Back button behavior within an InAppBrowser window with Cordova 3.6?带有 Cordova 3.6 的 InAppBrowser 窗口中的后退按钮行为?
【发布时间】:2014-10-07 08:28:23
【问题描述】:

我正在使用cordova 3.6编写一个移动应用程序,这个应用程序只是打开一个与我的网站的移动版本对应的外部url

var ref = window.open('http://www.stackoverflow.com', '_self', 'location=no');

如果使用 _self 作为目标,则返回按钮行为很好,因为它在浏览的页面中正常工作,但问题是历史堆栈中的最后一个返回完成返回到我的索引页面,然后再次打开我的网址!窗口上的事件也不起作用。如何退出?

var ref = window.open('http://www.stackoverflow.com', '_blank', 'location=no');

如果使用 _self 作为目标,则返回按钮的行为是不一样的。在浏览过的页面中没有返回,无论我们是什么,都只是索引页面上的返回。如何将行为修改为与 _self 相同?

我被这两种解决方案卡住了:(

注意:我看到了这个similar question 但建议的代码

dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    public void onDismiss(DialogInterface dialog) {     
                        closeDialog();
                    }
});

cordova 中不再存在 InAppBrowser.java 不再存在

【问题讨论】:

    标签: android cordova cordova-3 inappbrowser


    【解决方案1】:

    感谢 Kris Erikson 在this post 上的回答,我找到了使用cordova 3.6 的“_blank”选项目标的工作解决方案

    通过这些修改,硬件后退按钮可以在 InAppBrowser 的页面中使用。

    我以后复制他的工作解决方案

    转到 src/com/org/apache/corodova/inappbrowser 目录并编辑 InAppBrowserDialog.java: 改变

    public void onBackPressed () {
       if (this.inAppBrowser == null) {
          this.dismiss();
       } else {
          // better to go through the in inAppBrowser
          // because it does a clean up            
          this.inAppBrowser.closeDialog();           
       }
    }
    

    到

    public void onBackPressed () {
       if (this.inAppBrowser == null) {
          this.dismiss();
       } else {
          if (this.inAppBrowser.canGoBack()) {
             this.inAppBrowser.goBack();
          }  else {
             this.inAppBrowser.closeDialog();
          }
       }
    }
    

    然后进入InAppBrowser,找到goBack函数,改:

    /**
    * Checks to see if it is possible to go back one page in history, then does so.
    */
    private void goBack() {
       if (this.inAppWebView.canGoBack()) {
          this.inAppWebView.goBack();
       }
    }
    

    到

    /**
    * Checks to see if it is possible to go back one page in history, then does so.
    */
    public void goBack() {
       if (this.inAppWebView.canGoBack()) {
          this.inAppWebView.goBack();
       }
    }
    
    public boolean canGoBack() {
       return this.inAppWebView.canGoBack();
    }
    

    如果您找到避免修改java代码的更好解决方案,请发布

    【讨论】:

    • 好一个! Adobe 怎么会错过那个?
    • @Crio 我有同样的问题,但上面的代码不适用于cordova 4.0。你能建议一些东西吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 2021-10-25
    • 2016-11-29
    • 2021-09-27
    • 2013-05-10
    • 1970-01-01
    相关资源
    最近更新 更多