Page 1 of 1

navigate to page at startup

Posted: Sat Jun 22, 2013 4:58 pm
by jonwrig

I want to be able to navigate to a sign-in page if the expiry date held local storage variable has expired, or into the main menu if it is still valid. The problem is page navigates to the menu page as expected but immediately returns to the landing page! There is no code to do this on the menu page - how can I stop this happening?

Here is my landing page on-load javascript:

var x = localStorage.getItem("expires");
if (x){
var d2 = new Date(localStorage.getItem("expires"));
var d1 = new Date();
var timeDiff = Math.abs(d2.getTime() - d1.getTime());
if(timeDiff < 0){
Appery.navigateTo('loginPage');
}else{
Appery.navigateTo('Screen2MainMenu');
}
}else{
Appery.navigateTo('loginPage');
}


navigate to page at startup

Posted: Sat Jun 22, 2013 5:28 pm
by Alena Prykhodko

navigate to page at startup

Posted: Sat Jun 22, 2013 5:38 pm
by jonwrig

Sorry, Alena, this does not resolve my problem.
It navigates to the menu page, but then it flips back to the landing page.


navigate to page at startup

Posted: Sat Jun 22, 2013 6:19 pm
by jonwrig

Solved it by putting a timeout on the navigation:

var x = localStorage.getItem("expires");
if (x){
//alert(x);
var d2 = new Date(localStorage.getItem("expires"));
var d1 = new Date();
var timeDiff = Math.abs(d2.getTime() - d1.getTime());
if(timeDiff < 0){
//alert("expired");
setTimeout("Appery.navigateTo('loginPage')" , 1000);
}else{
//alert("Date still valid - sessionid = " + localStorage.getItem("sessionId"));
setTimeout("Appery.navigateTo('Screen2MainMenu', {reloadPage: true})" , 1000);
}
}else{
//alert("login default");
setTimeout("Appery.navigateTo('loginPage')" , 1000);
}


navigate to page at startup

Posted: Sat Jun 22, 2013 6:32 pm
by Alena Prykhodko

Thank you for sharing that.