2014-05-02 39 views
0

如何使用localStorage存儲我的應用程序的登錄憑據?我想它會在我退出應用程序時將它存儲在某個地方,然後當我再次打開應用程序時,這些字段將預先填入localStorage的信息。這是我的代碼到目前爲止。phonegate的localStorage將在退出應用程序後存儲內容?

function onDeviceReady() { 
     alert("ready"); 
     var email = window.localStorage.getItem("email"); 
     var password = window.localStorage.getItem("password"); 

     document.getElementById("email").value = email; 
     document.getElementById("password").value = password;  
    } 

    //If checkbox gets checked then save credentials, if unchecked then forget 
    function rememberMe() { 
     if(document.getElementById('remember_me').checked) { 
      alert("checked"); 
      window.localStorage.setItem("email", document.getElementById("email").value); 
      window.localStorage.setItem("password", docuement.getElementById("password").value); 
     } 
     else { 
      alert("unchecked"); 
      window.localstorage.clear(); 
     } 
    } 
+0

代碼無法正常工作? –

+0

不,在我退出並再次打開應用程序後,字段未預先填充來自localStorage的信息。 – romeo

+0

代碼似乎正在運行,嘗試在桌面瀏覽器中測試並調試執行,可能是流程不正確。 –

回答

0

localStorage的可容納object's數據,直到它被來自同一刪除,但是當你關閉標籤/瀏覽器的sessionStorage將清除數據。

0

最好的辦法是使用webSQLSQLite數據庫。當有人嘗試登錄時保存憑證,然後當有人打開應用程序時,通過從頁面加載數據庫或設備就緒功能中讀取數據來填充框。

相關問題