Jquery mobile,删除上一页 [英] Jquery mobile, remove previous page

查看:24
本文介绍了Jquery mobile,删除上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 phonegap 的 jquery mobile.我的应用程序有两个页面:登录页面和列表页面.登录成功后,用户将进入列表页面.之后,当他们按下手机(android)上的后退按钮时,他们将返回登录页面.我不想要这样的行为.我想要的是退出应用程序.

解决方案

正如我在这个问题中的回答:页面哈希和后退按钮问题 phonegap+Jquery

您可以更改页面而不将它们保留在浏览器历史记录中,如下所示:

$.mobile.changePage('#page', {reverse: false, changeHash: false});

不幸的是,我没有设法阻止初始页面保留在浏览器历史记录中,所以我使用了一种解决方法:

页面布局:

<!-- page_1 在源中的 page_loading 之前 --><div data-role="page" id="page_1">

<!-- page_loading 将首先显示--><div data-role="page" id="page_loading"><div data-role="内容"><h1><b>欢迎</b>

<div data-role="page" id="page_2">

jQuery:

函数 onBodyLoad(){//在 deviceready 之前转到 page_loading 而不将其保留在浏览器历史记录中$.mobile.changePage('#page_loading', {reverse: false, changeHash: false});document.addEventListener("deviceready", onDeviceReady, false);}函数 onDeviceReady(){//你的初始化代码在这里...//现在转到page_1而不将其保留在浏览器历史记录中,因为实际的第一页已经是#page_1$.mobile.changePage('#page_1', {reverse: false, changeHash: false});//你的代码在这里...}

这应该符合您的需求,试试吧.#page_loading"将是您的登录页面,page_1"将是您的列表页面...

I'm using jquery mobile with phonegap. My app has two pages: login page and list page. When login successfully, the user will go to the list page. Afterwards, when they press the back button on their phone (android), they will go back to the login page. I don't want behavior like this. What I want is to exit the app.

解决方案

As I answered in this question: page hash and backbutton issue phonegap+Jquery

You can change pages without keeping them in browser history like so:

$.mobile.changePage('#page', {reverse: false, changeHash: false});

Unfortunately, I didn't manage to prevent the initial page from staying in browser history, so I used a workaround:

Page layout:

<body>    
    <!-- page_1 before page_loading in source -->
    <div data-role="page" id="page_1">
    </div>
    <!-- page_loading will be shown first -->
    <div data-role="page" id="page_loading">
        <div data-role="content">
            <h1 >
                <b>welcome</b>
            </h1>
        </div>
    </div>
    <div data-role="page" id="page_2">
    </div>    
</body>

jQuery:

function onBodyLoad()
{   
    //go to page_loading before deviceready without keeping it in browser history
    $.mobile.changePage('#page_loading', {reverse: false, changeHash: false});
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady()
{   
    //your initialization code here...

    //now go to page_1 without keeping it in browser history since the actual first page was #page_1 already       
    $.mobile.changePage('#page_1', {reverse: false, changeHash: false});

    //your code here...
}

This should fit your needs, just try it out. "#page_loading" would be your login page, "page_1" your list page...

这篇关于Jquery mobile,删除上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
移动开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆