Autologin with Inappbrowser on an external website?

好久不见. 提交于 2019-12-02 10:05:09

问题


I've built a native app with Phonegap Build. Is there a way to autologin in webview on an external website (embedded with inappbrowser).

The app starts and then the users will be redirecting to the website for login. But the users have to put in their username and password again and again. is there a possibility to autologin? Ive read about localstorage. Is that possible with the inappbrowser on a external website (there is no access to the phonegap plugins I know).


回答1:


Yes, it should be possible. You just need to connect proper handler to loadstop event and then use local storage to store the usernames and passwords once submit is hit and if already existing, auto-fill them.

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);


来源:https://stackoverflow.com/questions/27766375/autologin-with-inappbrowser-on-an-external-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!