3
I have a problem with window.history.back(), for he is returning only one page.
I use the following function:
        <script type="text/javascript" charset="utf-8">
        // Wait for device API libraries to load
        //
        function onLoad() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }
        // device APIs are available
        //
        function onDeviceReady() {
            // Register the event listener
            document.addEventListener("backbutton", onBackKeyDown, false);
        }
        // Handle the back button
        //
        function onBackKeyDown() {
            if($('.upage:visible').attr("id") == 'listar_CELULAS'){
                var r=confirm("Você realmente deseja sair do aplicativo ?");
                if(r==true){
                    navigator.app.exitApp();
                }else{
                }
            }else{
                console.log("ta entrando aqui");
                window.history.back();
            }
        }
    </script>
I need to return everyone to the starting point of the stack. To place on the stack history use this function:
function activate_page(sel, have_state)
{
    var $dn = $(sel);
    var is_vis = $dn.is(":visible");
    if(!is_vis)
    {
        $dn.parents("body").find(".upage").addClass("hidden");
        $dn.removeClass("hidden");
    window.history.pushState({upage:sel}, sel, document.location.origin + document.location.pathname +sel);
    $(document).trigger("pagechange");
    }
}
Probably Ionic is part of this problem, in fact I’m not really understanding the moment that each one is doing something, follow my Ionic code:
angular.module('ionic')
  .run(function($ionicPlatform,$ionicPopup, $state,$ionicHistory){
    $ionicPlatform.registerBackButtonAction(function (event) {
      //console.log(window.history);
      if($state.current.name=="app.listar_CELULAS"){
        alert("entro aqui");
        navigator.app.exitApp();
      }
      else {
        //window.history.back();
      }
    }, 100);
});
Here is the function that theoretically populates the history of visited pages:
function activate_page(sel, have_state)
{
    var $dn = $(sel);
    var is_vis = $dn.is(":visible");
    if(!is_vis)
    {
        $dn.parents("body").find(".upage").addClass("hidden");
        $dn.removeClass("hidden");
        window.history.pushState({upage:sel}, sel, document.location.origin + document.location.pathname +sel);
        console.log(window.history);
        $(document).trigger("pagechange");
    }
}
Where is the error ?
Thanks for now.
Let’s go continue this discussion in chat.
– Guilherme Nascimento
I don’t want him to go back to the beginning I want him to break the queue, for example I went to pages (1,2,3,4,5) I clicked to return him back in the 4, ai da 4 went to 6 after 7 being like this (1,2,3,4,6,7) I click to return him back in the 6. This is what I need. @Guilherme
– Renan Rodrigues
@Renanrodrigues when I formulated the answer your question was confusing, I just didn’t really have time to test the Cordova. I think we had already reached a consensus in the chat no?
– Guilherme Nascimento
It had not worked, because it came back only one, I find that the window it records only the last page visited, I mean there was no way back. But my problem has not been solved.
– Renan Rodrigues
As to
windowrecord only one or more I don’t know, I think it works, the problem seems to me the environment of your application. As I said, I haven’t had time to install Phonegap and Cordova which is your case. Maybe you haven’t enabled the history. However I agreed that as soon as possible I would install and try to resolve and edit the answer ;)– Guilherme Nascimento
Ok, I await your contact, I will add the part of code that populates windows.history
– Renan Rodrigues
I updated the question.
– Renan Rodrigues