I basically need a custom function to be used only when, for example, the #reviews page is clicked on from the home page.
Here is the current code I am using:
$(document).bind("mobileinit", function(){
$('#reviews').live('pagebeforeshow',function(event){
var cpage = $.mobile.activePage.attr('id');
if (cpage == 'home') {
addPages();
}
});
});
The problem is, even though it is using ‘pagebeforeshow’ it is using the id of the page it is about to transition to as the active page, in this case ‘reviews’ rather than home, thus causing the if statement to fail.
So my question is, in this example, how would i get the id of the previous page, to make sure it is in fact coming from the #home page?
To complete the answer: you will get a jQuery object back, so to get the ID of the page do this:
data.prevPage is getting the previous page as jQuery object,
.attr(‘id’) is getting the id from that jQuery object.