JQuery mobile, delete previous page

I am using jquery mobile with telephony. My application has two pages: the login page and the list page. Upon successful login, the user will be redirected to the list page. Subsequently, when they press the back button on their Android phone, they return to the login page. I do not want this behavior. I want to exit the application.

+5
source share
4 answers

As I answered in this question: page hash and spam problem in the phone book + jQuery

You can change pages without saving them in your browser history:

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

, , :

:

<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...
}

, . "#page_loading" , "page_1" ...

+5

, changeHash: false , . .

+1

jQuery mobile (1.4+), script:

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

jQuery.mobile.changePage jQuery Mobile 1.4.0 1.5.0.

+1
source

Adding parameters for reverse and changeHash did not help me. using Cordova v1.6

I ended up redefining the onTouch method in my work with Android.

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (KeyEvent.KEYCODE_BACK == keyCode) {
        // Clear browsers history if user clicks back button
        clearHistory();
    }
    return super.onKeyUp(keyCode, event);
}
0
source

All Articles