带有phonegap的“后退"按钮(并查询手机吗?) [英] Back button with phonegap (and query mobile?)

查看:101
本文介绍了带有phonegap的“后退"按钮(并查询手机吗?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用jquery mobile和phonegap编写的应用程序中遇到问题.在浏览器中进行测试时,使用后退按钮没有任何问题(不涉及phonegap js).但是,一旦我尝试使用带phonegap js的设备,它就会崩溃.

I am having a problem with an application I am writing in jquery mobile and phonegap. While testing in the browser, I had no problems using the back button (no phonegap js involved). However once I try on a device with the phonegap js it breaks.

复制步骤:

  1. 加载应用
  2. 访问多个页面(内部使用#链接)
  3. 在任何地方(使用js控制台,或通过触发调用它的东西)单击后退"按钮或调用history.back().

在浏览器(铬,firefox等)上,它返回一个页面"(无论以前是什么,都返回到上一个#链接).这是首选的行为.

On the browser (chromium, firefox etc), it goes back one 'page' (to the previous # link whatever it was). This is the preferred behaviour.

在设备(iPhone 4,iPhone模拟器,Android 2.2(设备),Android 3.2(设备))上,它会转到首页/着陆页(index.html文件中的第一个页面").

On the device (iPhone 4, iPhone simulator, Android 2.2 (device), Android 3.2 (device)), it goes to the first/landing page (the first 'page' in the index.html file).

我怀疑问题出在手机间隙.有没有办法还原为首选行为或浏览器?

I suspect that the problem is with phonegap. Is there a way to revert to the preferred behaviour or the browser?

推荐答案

问题是由我正在使用的数据URL中的空格引起的.似乎桌面浏览器可以正确处理空间,但是移动浏览器将空间转换为%20%字符. jQuery mobile尝试使用空格,但浏览器仅记住更改的字符.

The problem was caused by a space in the data url I was using. It seems that the desktop browsers can handle a space properly, however the mobile browsers convert the space into a %20% character. jQuery mobile attempts to use a space, but the browser only remembers the altered character.

jqm页面具有data-url属性,该属性允许您将多个页面存储在一个html文档中.

The jqm page has a data-url attribute that allows you to store multiple pages inside one html document.

<html>
<head> ... </head>
<body>
<div data-role="page" data-url="page-one"> ... </div>
<div data-role="page" data-url="page two"> ... </div>
</body>
</html>

可以通过几种方式加载第一页...

The first pages can be loaded in a few ways...

在文档中

<a href="#page-one">

或通过javascript

or through javascript

$.mobile.changePage("#page-one");

我遇到的问题是数据URL为page two的页面.在桌面浏览器上,空间得以保留,内置在jqm中的自定义历史记录控件继续按预期运行.但是在移动浏览器上,该空间变成了转义空间,jqm历史记录控件无法识别或跟踪该空间.

The problem I had was with the page with the data-url page two. On the desktop browsers the space was maintained, and the customized history control built into jqm continued to function as expected. but on the mobile browsers, the space turned into an escaped space, which the jqm history control did not recognize or track.

这篇关于带有phonegap的“后退"按钮(并查询手机吗?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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