I ran in to a problem while developing a mobile app using Phonegap & jQuery Mobile.
I’ve an entry condition to be checked everytime before a page is shown, say page A. If the condition goes false, i navigate the app to another page, say page X. I did that using the page event pagebeforeshow.
But my problem is that…
Even though i used the pagebeforeshow event, the page page A is getting shown. Ie; the page A is shown once and then the apps navigates to page X. I dont want this page A to be displayed if the condition is wrong. I mean, cancel the that page show event and move on to other page.
Hope you’ve got what i asked.
Why it is so? is there any other method through which i can accomplish my task perfectly.
Any kind of helps would be deeply appreciated! 🙂
Don’t use
pagebeforeshowevent in this case, that is one of the last page events to trigger. At that point second page is already created and ready to be shown. This must be done before second page is about to be created.First take a look at my other ARTICLE, there you will find a list of page events during a transition from page one to page two. Or it can be found HERE.
Now about your problem, here’s a code that you can use to fix your problem. It is using
pagebeforechangeevent (which is a first event to trigger during a page transition):And here’s a live
jsFiddleexample: http://jsfiddle.net/Gajotres/3PhKZ/, you should click on a next button to trigger a page change.