Baked Inhalf
Baked Inhalf

Reputation: 3735

Update one page with jQuery, in single html file

I've got a single html with 5 pages + navbar. To force a refresh of one page I use this:

$("#page3").on("pagecreate", function(e) {});

It works the first time, but I want it to update every time I visit the page. I know there is .trigger("create"), and "refresh", but I can't get it to work properly...

jQuery Mobile 1.4.0

Upvotes: 4

Views: 763

Answers (1)

Omar
Omar

Reputation: 31732

You need to listen to pageContainer event in order to determine which page is active and accordingly run the functions you want.

The new events can't be attached to a specific page, unlike successor versions of jQuery Mobile. Once an event is occurred, retrieve ActivePage's ID.

$(document).on("pagecontainerbeforeshow", function (e, ui) {
  var activePage = $.mobile.pageContainer.pagecontainer("getActivePage")[0].id;
  if(activePage == "page3") {
    doSomething();
  }
});

Demo

Upvotes: 5

Related Questions