jquery mobile, browser back button navigation

心不动则不痛 提交于 2019-12-23 02:36:40

问题


I have a multipage form with #p1,#p2,#p3. Once I submit the form, and when I try to click back browser button, it should go to #p1 with empty form fields. it is possible wiith Jquery Mobile?


回答1:


I would override the backbutton and check for which page is the active page then based on the page do whatever house cleaning you need...

I submitted an example to another question really similar to this:

BackButton Handler

Where I have Options, Popup and HomePage you might just need P3 and when the activePage is equal to P3 clear your form and show P1.

    function pageinit() {
        document.addEventListener("deviceready", deviceInfo, true);
    }

    function deviceInfo() {
        document.addEventListener("backbutton", onBackButton, true);
    } 

    function onBackButton(e) {
        try{
            var activePage = $.mobile.activePage.attr('id');

            if(activePage == 'P3'){
                clearForm(); // <-- Calls your function to clear the form...
                window.location.href='index.html#P1';

            } else if(activePage == 'P1'){

                function checkButtonSelection(iValue){
                    if (iValue == 2){
                        navigator.app.exitApp();
                    }
                }

                e.preventDefault();
                navigator.notification.confirm(
                    "Are you sure you want to EXIT the program?",
                    checkButtonSelection,
                    'EXIT APP:',
                    'Cancel,OK');

            } else {
                navigator.app.backHistory();
            }
        } catch(e){ console.log('Exception: '+e,3); }
    }


来源:https://stackoverflow.com/questions/12569389/jquery-mobile-browser-back-button-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!