在外部网站上使用Inappbrowser自动登录

Autologin with Inappbrowser on an external website?

本文关键字:Inappbrowser 登录 外部 网站      更新时间:2023-09-26

我用Phonegap Build构建了一个原生应用程序。有没有办法在外部网站的网络视图中自动登录(嵌入了应用程序浏览器)。

应用程序启动,然后用户将重定向到网站进行登录。但是用户必须一次又一次地输入用户名和密码。是否可以自动登录?我读过关于本地存储的信息。外部网站上的 inappbrowser 是否可以做到这一点(我知道无法访问 phonegap 插件)。

是的,应该是可能的。您只需要将适当的处理程序连接到 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);