问题与window.history使用JQuery / Javascript在Cordova应用程序在IOS9 [英] Problems with window.history using JQuery/Javascript on Cordova app in IOS9

查看:352
本文介绍了问题与window.history使用JQuery / Javascript在Cordova应用程序在IOS9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用IOS9(测试版)下的Cordova应用程式时遇到问题。我使用最新的Cordova和JQuery移动生成。 window.history未更新,这导致以下失败:




  • window.history.go(-1)无法返回

  • window.history.length已停留在1,即使您浏览三页也是如此



  • 我已将以下示例代码放在一起,当作为单独的Cordova应用程序运行时失败IOS9(beta),但工作正常,如果你从IOS9(beta)浏览器(下面的链接)运行它。事实上,它是从移动浏览器运行而不是作为应用程序,这让我相信它可能是一个Cordova问题。



    在示例中 - 有三个页面。从主页 - >选项 - > HopOpts导航,然后点击取消按钮应该带我们回到一个页面,但不是在cordova应用程序。我单独尝试为该按钮附加按钮处理程序,并确认window.history的深度为1(应为3),并且window.history.go(-1)无法移回。



    示例HTML文件位于: http://home.jejaju.com/BeerSmith2.html



    要在Cordova下以应用程序运行,您需要删除靠近顶部的Cordova.js行周围的注释块。正如我上面指出的,它在浏览器中正常工作,即使在IOS9浏览器上,但取消按钮作为独立cordova应用程序失败。



    有一个线索为什么window.history不更新和反向链接不能正常工作这个简单的Cordova应用程序和IOS9(测试版)?这两个测试用例中唯一改变的是Cordova.js。

    解决方案

    我看到这是几个星期前,发表评论,以防其他人遇到。这听起来像可能与在iOS 9中的哈希更改生成的导航事件相关。如果是,您可以将其添加到您的index.html以禁用哈希侦听:



    (需要在jquery.js和jquery.mobile-1.4.5.js之间转换,如下所示)

      ; script type =text / javascriptcharset =utf-8src =js / jquery.js>< / script> 
    < script type =text / javascript>
    $(document).bind(mobileinit,function(){
    $ .mobile.hashListeningEnabled = false;
    });
    < / script>
    < script type =text / javascriptcharset =utf-8src =js / jquery.mobile-1.4.5.js>< / script&


    I'm having trouble with a Cordova app under IOS9 (beta). I'm using latest Cordova and JQuery mobile builds. The window.history is not getting updated which is causing the following failures:

    • window.history.go(-1) fails to go back a page
    • window.history.length is stuck at 1 even if you navigate three pages deep
    • Links marked in jQuery as data-rel="back" fail to go back when pressed

    I've put together the following sample code which fails when run as a separate Cordova app under IOS9(beta) but works properly if you run it from an IOS9(beta) browser (link below). The fact that it runs from the mobile browser but not as an app leads me to believe it may be a Cordova issue.

    In the sample - there are three pages. Navigating from Home->Options->HopOpts and then hitting the cancel button should take us back a page but does not in the cordova app. I've separately tried attaching a button handler to that button and confirmed that window.history has a depth of 1 (should be 3) and also window.history.go(-1) fails to move back.

    The sample HTML file is here: http://home.jejaju.com/BeerSmith2.html

    To run it under Cordova as an app, you need to remove the comment blocks around the "Cordova.js" line near the top. As I point out above it works properly in a browser, even on an IOS9 browser, but the cancel button fails as a standalone cordova app.

    So the question is does anyone have a clue why window.history is not updating and back links don't work properly for this simple Cordova app and IOS9(beta)? The only thing changed in the two test cases is Cordova.js.

    解决方案

    I see this was a couple weeks ago, but I'll post this in case someone else runs into it. It sounds like it may be related to navigation events generated by a hash change in iOS 9. If so, you can add this to your index.html to disable the hash listening:

    (needs to go between the jquery.js and jquery.mobile-1.4.5.js as shown here)

    <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
    <script type="text/javascript">
      $(document).bind("mobileinit", function(){
          $.mobile.hashListeningEnabled = false;
      });
    </script>  
    <script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.4.5.js"></script>
    

    这篇关于问题与window.history使用JQuery / Javascript在Cordova应用程序在IOS9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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