omega
omega

Reputation: 43863

How to detect page show event when pressing back in jquery mobile?

In my jquery mobile app, I want to run a function when the default page shows. This code works

    $(document).unbind("pageshow").on("pageshow","#login-page",function(){
        GLOBAL_DATA.user = null;
        alert("reset");
    });

But the problem is when I click a button to go to another page, then when I click the back button to go back to the default page, the pageshow function does not trigger. How can I get it to do that?

Thanks

Upvotes: 0

Views: 1046

Answers (1)

ezanker
ezanker

Reputation: 24738

For jQM 1.4.x try using the pagecontainer widget show event instead:

$(document).on( "pagecontainershow", function( event, ui ) {
  alert( "The page being shown is: " + ui.toPage.prop("id") );
});

DEMO

Upvotes: 1

Related Questions