2013-10-11 56 views
2

我正在使用jQuery手机,PHP和MySQL构建PhoneGap应用程序。它将需要用户认证。我知道文件index.html会在应用程序像任何其他Web应用程序一样被调用时立即生效。我的问题是:如何强制我的应用首先转到login.html,而不是转到index.html,然后根据用户条目将它引导到index.html或不。 我知道如何做计算机应用程序,但对于这种情况下index.html应该是登录页面或有任何其他方式来解决这个重定向?PhoneGap登录表重定向

回答

0

你必须检查,如果用户登录或不上的index.html JavaScript的,如果他不是那么重定向到login.html的其他执行代码

0

检查localStorage的(或者你正在使用的任何机制以确定如果用户使用,当然JavaScript的index.html的登录),如果他们没有登录,使用基本的JavaScript将用户重定向到登录页面:

window.location.href = "http://stackoverflow.com"; 

有大量的文档如果您使用该机制,请在PhoneGap网站上关于LocalStorage。

有趣的事实:PhoneGap不支持PHP。但它支持在服务器上对PHP页面进行ajax调用。

+0

这工作!另外我可以看到$ .mobile.changePage(“main.html”)也可以正常工作。谢谢。 –

+0

“接受”如果答案足够。 –

+0

我试过使用这种方式,但更好的方式是使用$ .mobile.changePage(“main.html”); –

2
$('#mainpage').on('pageshow', function(event) { 
    var user = jQuery.parseJSON(localStorage.getItem('userInfo')); 
    if (user == null) { 
     $.mobile.changePage('#loginpage'); 
    } 
}); 

$('#loginpage').on('pageshow', function(event) { 

    var user = jQuery.parseJSON(localStorage.getItem('userInfo')); 
    if (user != null) { 
     $.mobile.changePage('#mainpage'); 
    } 
}); 

如果登录成功localStorage.setItem('userInfo', ...);然后$.mobile.changePage('#mainpage');