2013-10-11 62 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');