简体   繁体   English

jQueryMobile PhoneGap应用程序上偶尔没有响应的后退按钮

[英]Occasionally unresponsive back button on jQueryMobile PhoneGap app

I've created an app using jQuery Mobile (1.3.1) and PhoneGap (3.4), and have skinned it to have a fairly "flat" looking interface: 我使用jQuery Mobile(1.3.1)和PhoneGap(3.4)创建了一个应用程序,并将其设置为具有相当“平坦”外观的界面:

主屏幕

I'm having some trouble where, only on iOS, and only occasionally, the "back" button on only one certain screen becomes unresponsive. 我遇到了一些麻烦,只有在iOS上才有,而且只是偶尔,只有一个屏幕上的“后退”按钮变得没有响应。 The same HTML & CSS for the back button on other screens seems fine, it's just this one screen. 其他屏幕上后退按钮的相同HTML和CSS似乎很好,它只是这一个屏幕。 Here it is in chrome with the button selected in devtools to highlight its hit area: 这里是chrome,在devtools中选中了按钮以突出显示其命中区域:

返回键

And just for good measure, here's the header as well: 只是为了好的衡量标准,这里也是标题:

头

The code for this screen's header is the same for just about every screen in the app: 此屏幕标题的代码对于应用中的几乎每个屏幕都是相同的:

<div data-role="header" data-theme="e" data-position="fixed" data-tap-toggle="false">
    <h1>Event Detail</h1>
    <a data-rel="back">Back</a>
</div>

We've found that, should the user get stuck on this screen and force-close the app, the button seems to work as expected in subsequent use. 我们发现,如果用户卡在此屏幕上并强制关闭应用程序,则按钮似乎在后续使用中按预期工作。

So my current theory is that the header is somehow getting in the way of the back button (sometimes). 所以我现在的理论是标题以某种方式妨碍了后退按钮(有时候)。 The fact that it's not every time makes me not really believe this theory completely, however. 但事实并非每次都让我完全不相信这个理论。

The button has its z-index set to 10 and the header's z-index is left at the default (which is 1, correct?). 该按钮的z-index设置为10,标题的z-index保留为默认值(1,正确?)。 So even if it were the header getting in the way, my understanding is that the z-index of 10 should put the button "on top" and give it the first opportunity to receive the click/tap event. 因此即使是标题阻碍了我的理解,我的理解是10的z-index应该将按钮“置于顶部”并为其提供第一次接收点击/点击事件的机会。

The app uses jQueryMobile 1.3.1 because of the timing of when and how it was created, and upgrading is not a reasonable option at this moment. 该应用程序使用jQueryMobile 1.3.1,因为它的创建时间和方式的时间安排,此时升级不是一个合理的选择。 (There have been a significant number of breaking changes in 1.4.x) (1.4.x中出现了大量的重大变化)

I have debugged the app on both iOS and Android and no JavaScript errors are thrown. 我已经在iOS和Android上调试了应用程序,并且没有抛出任何JavaScript错误。 I'm at a total loss for what to do. 我完全不知道该做什么。 This app is in the process of rolling out to thousands of users and there's a high likelihood that many, possibly most, will run into this bug. 这个应用程序正在向成千上万的用户推出,并且很可能很多人(可能是大多数人)会遇到这个错误。 I would rather not have to explain (with my tail between my legs) that force-closing is the only way to fix this... but that's what I've been doing so far. 我宁愿不必解释(我的双腿之间的尾巴)强制关闭是解决这个问题的唯一方法......但这就是我到目前为止所做的。

Does anyone have any advice or ideas on how to fix this? 有没有人对如何解决这个问题有任何建议或想法?


Update 1: 更新1:

I've noticed while remote-debugging the app in Safari over USB that I can watch the classes on the back button change, when tapped, from ui-btn-up-e to ui-btn-hover-e briefly to ui-btn-down-e and back to ui-btn-up-e -- and yet the app is not going back! 我注意到在Safari上通过USB远程调试应用程序时,我可以看到后退按钮上的类更改,当被点击时,从ui-btn-up-eui-btn-hover-e简单到ui-btn-down-e并回到ui-btn-up-e - 但应用程序不会再回来了! :( :(

And as requested, here is the CSS applied to the header, the H1, and the back button: (just the "computed" final values, not all of the intermediary overridden values) 根据要求,这里是应用于标题,H1和后退按钮的CSS :(只是“计算”的最终值,而不是所有中间重写的值)

header div: 标题div:

-webkit-background-clip: border-box;
-webkit-background-origin: padding-box;
-webkit-background-size: auto;
background-attachment: scroll;
background-clip: border-box;
background-color: rgb(179, 27, 27);
background-image: none;
background-origin: padding-box;
background-size: auto;
border-bottom-color: rgb(179, 27, 27);
border-bottom-style: solid;
border-bottom-width: 1px;
border-image-outset: 0px;
border-image-repeat: stretch;
border-image-slice: 100%;
border-image-source: none;
border-image-width: 1;
border-left-color: rgb(179, 27, 27);
border-left-style: solid;
border-left-width: 0px;
border-right-color: rgb(179, 27, 27);
border-right-style: solid;
border-right-width: 0px;
border-top-color: rgb(179, 27, 27);
border-top-style: solid;
border-top-width: 1px;
color: rgb(255, 255, 255);
display: block;
font-family: MyriadPro, Helvetica, sans-serif;
font-weight: bold;
height: 45px;
left: 0px;
padding-top: 1px;
position: fixed;
right: 0px;
text-shadow: rgb(85, 85, 85) 0px 1px 0px;
top: -1px;
width: 320px;
z-index: 1000;
zoom: 1;

H1: H1:

color: rgb(255, 255, 255);
display: block;
font-family: MyriadPro, Helvetica, sans-serif;
font-size: 18px;
font-weight: bold;
height: 23px;
margin-bottom: 10px;
margin-left: 48px;
margin-right: 48px;
margin-top: 12px;
min-height: 19.799999237060547px;
outline-color: rgb(255, 255, 255);
outline-style: none;
outline-width: 0px;
overflow-x: hidden;
overflow-y: hidden;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
text-align: center;
text-overflow: ellipsis;
text-shadow: rgb(85, 85, 85) 0px 1px 0px;
white-space: nowrap;
width: 224px;
zoom: 1;

Back button: 返回键:

-webkit-background-clip: border-box;
-webkit-background-origin: padding-box;
-webkit-background-size: auto;
-webkit-box-shadow: none;
background-attachment: scroll;
background-clip: border-box;
background-color: rgb(179, 27, 27);
background-image: none;
background-origin: padding-box;
background-size: auto;
border-bottom-color: rgb(179, 27, 27);
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-style: solid;
border-bottom-width: 0px;
border-image-outset: 0px;
border-image-repeat: stretch;
border-image-slice: 100%;
border-image-source: none;
border-image-width: 1;
border-left-color: rgb(179, 27, 27);
border-left-style: solid;
border-left-width: 0px;
border-right-color: rgb(179, 27, 27);
border-right-style: solid;
border-right-width: 0px;
border-top-color: rgb(179, 27, 27);
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border-top-style: solid;
border-top-width: 0px;
box-shadow: none;
color: rgb(255, 255, 255);
cursor: pointer;
display: block;
font-family: MyriadPro, Helvetica, sans-serif;
font-weight: bold;
height: 31px;
left: 5px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
position: absolute;
text-align: center;
text-decoration: none solid rgb(255, 255, 255);
text-shadow: rgb(0, 0, 0) 0px 1px 0px;
top: 15px;
vertical-align: middle;
width: 60px;
z-index: 10;
zoom: 1;

First let me tell you that your problem probably don't have nothing to do with button/header CSS. 首先让我告诉你,你的问题可能与按钮/标题CSS没有任何关系。 If this error is showing sporadically and only during back function your problem is happening probably due to data-rel="back" functionality. 如果此错误偶尔出现并且仅在后退功能期间出现问题,则可能是由于data-rel =“back”功能。

Unlike classic href page movement, data-rel="back" uses javascript navigation history which may or may not work depending on your app content. 与传统的href页面移动不同, data-rel =“back”使用javascript导航历史记录,根据您的应用内容,该历史记录可能有效也可能无效。 Because jQuery Mobile uses AJAX for page handling (and from your button I can see you are using this method) it also has its own way of handling navigation history. 因为jQuery Mobile使用AJAX进行页面处理(从你的按钮我可以看到你正在使用这种方法),它也有自己的处理导航历史的方法。

Now, lets say your application heavily uses dynamic content generation (including content removal), and for example previous page is removed from the DOM, in this case data-rel="back" will not work. 现在,假设您的应用程序大量使用动态内容生成(包括内容删除),例如从DOM中删除上一页,在这种情况下, data-rel =“back”将不起作用。 If previous page don't exist you will not be able to move back. 如果前一页不存在,您将无法返回。 There are several other factors that can also affect this functionality. 还有其他一些因素也会影响此功能。

What you can do to solve this problem: 你可以做些什么来解决这个问题:

  1. Give this button a class name or even an id. 给这个按钮一个类名甚至一个id。 After that bind a click event to it (vclick even better because it is as fast as tap, without 300ms delay, and works on desktop and mobile browsers a like) and add a console output each time you click on this button. 之后将点击事件绑定到它(vclick甚至更好,因为它与点击一样快,没有300毫秒延迟,并且可以在桌面和移动浏览器上工作)并且每次单击此按钮时添加控制台输出。 So you would do it like this: 所以你会这样做:

     $(document).on('vclick', '#button-ID-goes-here', function(){ console.log('Problematic button'); }); 

    This way you can test if button has been clicked. 这样您就可以测试是否单击了按钮。

  2. Next thing is little bit complicated. 接下来的事情有点复杂。 You never posted your page HTML but looking at your page image I think you are using correct jQuery Mobile paradigm, basically you are using data-role="page" div containers as page containers. 您从未发布过您的页面HTML,但查看您的页面图像我认为您使用的是正确的jQuery Mobile范例,基本上您使用的是data-role =“page” div容器作为页面容器。 You would be amazed how many jQuery Mobile developers don't know/understand they need/must have it if they want a proper jQuery Mobile app. 如果他们想要一个合适的jQuery Mobile应用程序,你会惊讶于有多少jQuery Mobile开发人员不知道/理解他们需要/必须拥有它。

    Take a look at a page that holds this button in its header. 看一下在标题中包含此按钮的页面。 Bind a pagebeforeshow event to that page and monitor will it trigger, and if it triggers you can use it to show previous and next page. pagebeforeshow事件绑定到该页面,监视器将触发,如果触发,您可以使用它来显示上一页和下一页。

    Working example: http://jsfiddle.net/Gajotres/vds2U/72/ 工作示例: http//jsfiddle.net/Gajotres/vds2U/72/

     $(document).on('pagebeforeshow', '.ui-page',function (e, data) { alert("Previous page : " + data.prevPage.attr('id') + " - Next page: " + $.mobile.activePage.attr('id')); }); 

    Use this solution to check if next page is correct and if it even exist. 使用此解决方案检查下一页是否正确以及是否存在。 If this page event is not triggering when you click back button then something bad is happening. 如果单击“后退”按钮时未触发此页面事件,则会发生错误。

  3. Use this next code as a workaround. 使用下一个代码作为解决方法。 Basically use page events and remember your previous page. 基本上使用页面事件并记住您的上一页。 Because you are currently using back button this solution will be viable here. 因为您当前正在使用后退按钮,所以此处的解决方案是可行的。 We will use pagebeforeshow event to find out our previous page, we will store it into some JavaScript object (it will persist between page transitions). 我们将使用pagebeforeshow事件来查找我们的上一页,我们将它存储到一些JavaScript对象中(它将在页面转换之间保持不变)。

    Working example: http://jsfiddle.net/Gajotres/vds2U/73/ 工作示例: http//jsfiddle.net/Gajotres/vds2U/73/

     $(document).on('pagebeforeshow', '#second',function (e, data) { pageHandler.prevPage = data.prevPage.attr('id'); $(document).on('click', '#custom-back-button',function () { $.mobile.changePage( "#"+pageHandler.prevPage); }); }); var pageHandler = { prevPage : null } 

    This is complete custom solution to data-rel="back" page handling. 这是data-rel =“back”页面处理的完整自定义解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM