Nirav Limbasiya
Nirav Limbasiya

Reputation: 1

How to cancel previous page's pageshow event when user press back button on current page in phonegap ios

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.

Upvotes: 0

Views: 498

Answers (1)

Omar
Omar

Reputation: 31732

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!');
 }
});

Upvotes: 1

Related Questions