2015-01-04 50 views
0

我用Phonegap Build構建了一個本地應用程序。是否有一種方法可以在外部網站上使用webview進行自動登錄(使用inappbrowser嵌入)。在外部網站上使用Inappbrowser自動登錄?

該應用程序啓動,然後用戶將重定向到網站登錄。但用戶必須一次又一次輸入用戶名和密碼。有沒有可能自動登錄?我讀過關於本地存儲的內容。這可能與外部網站上的inappbrowser(沒有我知道的phonegap插件的訪問)。

回答

1

是的,應該是可以的。您只需要連接正確的處理程序到loadstop事件,然後使用本地存儲來存儲用戶名和密碼,一旦提交被擊中,並且如果已經存在,自動填充它們。

function loadStopped() { 
    // Here use JavaScript to manipulate the actual page on hand. 
    // Can't really give better description about what to do, but something like this: 
    var username = ""; 
    if (localStorage.getItem("username") !== null) { 
     username = localStorage.getItem("username"); 
    } 
    var password = ""; 
    if (localStorage.getItem("password") !== null) { 
     password = localStorage.getItem("password"); 
    } 
    document.getElementById("username_field").value = username; 
    document.getElementById("password_field").value = password; 
    // document.getElementById("the_form").submit(); 
    document.getElementById("the_form").addEventListener("submit", function() { 
     localStorage.setItem("username", document.getElementById("username_field").value); 
     localStorage.setItem("password", document.getElementById("password_field").value); 
    }); 
} 
ref = window.open('http://google.com', '_self', 'location=yes'); 
ref.addEventListener('loadstop', loadStopped); 
+0

謝謝。但我理解正確嗎?我需要將腳本輸入到Phonegap的index.html中,然後重定向到登錄頁面並自動登錄? – Bianca 2015-01-04 17:17:54

+0

既然你說你使用InAppBrowser,這意味着你使用_window.open_,對吧?腳本應該用在你打開InAppBrowser頁面的地方。 – 2015-01-04 17:28:35

+0

我使用 在我的index.html phonegap。對不起,我的問題:我必須輸入你的腳本?在index.html或外部頁面test.de/login? – Bianca 2015-01-04 17:55:54