Phonegap + jQuery Mobile + Windows Phone:“后退"按钮问题 [英] Phonegap +jquery mobile + windows phone: Back button issue

查看:107
本文介绍了Phonegap + jQuery Mobile + Windows Phone:“后退"按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Windows Phone开发一个应用程序.除了(设备的)后退"按钮外,该应用程序本身运行正常.后退按钮可以正确地向后导航,直到停下来的某个点.此时,它显示了AJAX加载程序.如果再次按下返回按钮,则该应用程序将关闭.

I'm developing an app for windows phone. The app itself is working fine except for the back button (of the device). The back button can navigate back correctly until a certain point where it stops. At this point it shows the AJAX loader. If the back button is pressed again, the app closes.

我的应用程序的结构如下(我使用的是多页结构):

The structure of my app is as follows (I'm using a multi-page structure):

应用加载->用户必须选择语言->带有其他页面按钮的主屏幕

App loads -> user has to pick language -> main screen with buttons to other pages

在主屏幕上,用户可以进一步导航到应用程序.后退按钮正常工作,直到必须再次显示主屏幕为止.

At the main screen the user can navigate further into the app. The back button works correctly until the main screen has to be show again.

以下是主屏幕的示例:

<div data-role="page" id="zero">
  <div data-role="content">
    <a href="#one" data-role="button" id="button-one" data-icon="plus">button-one</a>
    <a href="#two" data-role="button" id="button-two" data-icon="plus">button-two</a>
    <a href="#three" data-role="button" id="button-three" data-icon="plus">button-three</a>
    <a href="javascript:randomFunction();" data-role="button" id="button-four" data-icon="plus">button-four</a>
  </div>
</div>

我使用一些按钮来激活javascript功能.这些功能结束时,我使用$.mobile.changePage("#four");导航到页面.

I use a few buttons that activate a javascript function. At the end of these functions, I use $.mobile.changePage("#four"); to navigate to the page.

所有按钮都可以正常工作,但是当导航回到主屏幕时,它将停止并显示AJAX加载器.

All of the buttons work correctly, but when navigating back to the main screen, it stops and shows the AJAX loader.

也许是一些有用的信息-我的设备就绪功能如下所示:

Maybe some useful information - my device ready function looks like this:

*如果localstorage包含该语言的值,请设置语言并导航至主屏幕.

*If localstorage contains a value for the language, set the language and navigate to the main screen.

*如果本地存储中不包含该语言的值,请导航至用户可以选择该语言的页面.

*If the localstorage does not contain a value for the language, navigate to the page where the user can choose the language.

注意:在用户可以选择一种语言的页面上按返回按钮时,该应用程序将关闭(正常),此后,用户将导航到主屏幕.如果在此按下后退按钮,则应用程序也会关闭.我觉得这有点奇怪,因为我认为它必须导航回到语言选项页面.

NOTE: when pressing the back button at the page where the user can choose a language, the app closes (normal), after this, the user is navigated to the main screen. If the back button is pressed here, the app closes as well. I find this a bit odd, because I think it has to navigate back to the language option page.

推荐答案

我不知道您使用的Windows Phone版本是什么,但是WP 8.1遇到了一些后退按钮问题. cordova后退按钮事件似乎没有上班.我为Windows Phone制作了自定义的后退按钮实现.

I dont know what Windows Phone version you are using but I ran into some back button issues with WP 8.1. The cordova back button event doesn't seem to work. I made a custom back button implementation for Windows Phone.

WinJS.Application.addEventListener("backclick", function (evt) {
    if (!jQuery.mobile.activePage.is("#mainPage")) {
        history.back();
        // Prevent the default behavior by returning true. evt.preventDefault doesn't cancel the external code.
        return true;
    }
    // Execute the default behavior.
    return false;
};

这篇关于Phonegap + jQuery Mobile + Windows Phone:“后退"按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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