0

I am developing one app that uses iScroller to display list of products,

I have used the pageshow event for loading the list of product, due to some circumstances i am not able to use the pageinit().

Issue is that when i click on any product it shows product detail page, but on product detail page when i click on back button, it again call the pageshow() of the product list page.

I dont want to run the pageshow() when user clicks on back button on detail page, other then this back button i want to run the pageshow() from everywhere else.

Please tell me how to solve this scenario.

Omar
  • 32,302
  • 9
  • 69
  • 112

1 Answers1

1

The below example uses a variable to check whether back-button was clicked to view #products page. Once user navigate to from #products to #details and back using back-button it will alert that #products was viewed and thus you can stop reloading data again.

However, if a user navigate to other pages and back to #products page, it will work normally as it hasn't been viewed.

Demo

var viewed = false;

$(document).on('click', '.backbtn', function () {
 viewed = true;
});

$(document).on('pagebeforeshow', '#products', function () {
 if (viewed) {
  alert('page has been viewed');
  viewed = false;
 }
 else {
  alert('first visit!');
 }
});
Omar
  • 32,302
  • 9
  • 69
  • 112
  • thanks for your help, but this solution works when we use single HTML file for two DIVs that are page, but when i create two HTML file separately then it want work. – Nirav Limbasiya May 09 '13 at 05:19
  • then you need to pass parameters between pages, check this answer http://stackoverflow.com/questions/14776387/jquery-mobile-sending-data-from-one-page-to-the-another/14776523#14776523 @NiravLimbasiya – Omar May 09 '13 at 09:08