Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 755
Baked Inhalf Avatar asked Nov 06 '25 18:11

Baked Inhalf


1 Answers

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

like image 91
Omar Avatar answered Nov 08 '25 12:11

Omar