Autologin with Inappbrowser on an external website

2020-04-19 08:51发布

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条回答
三岁会撩人
2楼-- · 2020-04-19 09:12

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);
查看更多
登录 后发表回答