且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery Mobile的,浏览器后退按钮导航

更新时间:2023-10-05 16:43:22

我会重写后退按钮并为您的页面是活动页面,然后根据页面上做任何你需要的房子打扫...

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处理器

在那里我有选项,弹出和主页,你可能只需要P3,当activePage等于P3清晰的形式和节目P1。

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); }
    }