pageshow在apache cordova中无效

时间:2015-12-15 19:52:17

标签: angularjs cordova phonegap-plugins cordova-plugins visual-studio-cordova

您好我正在尝试实现“pageshow”因为我需要阻止返回,如果要使用的页面按钮是login.Porém方法“pageshow”没有被调用,所以我不能应用逻辑:

    // and then run "window.location.reload()" in the JavaScript Console.
    (function () {
        "use strict";
        var pageHistoryCount = 0;
        var goingBack = false;

        document.addEventListener('deviceready', onDeviceReady.bind(this), false);

        function onDeviceReady() {
            document.addEventListener('pause', onPause.bind(this), false);
            document.addEventListener('resume', onResume.bind(this), false);
            document.addEventListener('backbutton', backButtonHandler, false);
            $(document).bind("pageshow", function (e, data) {
                console.log("AAAAAAAAAAAAAAA");
                if (goingBack) {
                    goingBack = false;
                } else {
                    pageHistoryCount++;
                    console.log("HERE");
                }
            });
            // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
        };        
        function onPause() {
        };
        function onResume() {
        };
        function exitApp() {
            navigator.app.exitApp();
        };
        function backButtonHandler(e) {
            e.preventDefault();
            console.log(pageHistoryCount);
            if (pageHistoryCount > 0) pageHistoryCount--;
            if (pageHistoryCount == 0) {

            } else {
                goingBack = true;
                console.log("Going back to page #" + pageHistoryCount);
                window.history.back();
            }

            //Here implement the back button handler
        };      
    })();

0 个答案:

没有答案