在外部网站上使用Inappbrowser自动登录? [英] Autologin with Inappbrowser on an external website?

查看:439
本文介绍了在外部网站上使用Inappbrowser自动登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Phonegap Build构建了一个原生应用程序。有一种方法在外部网站上的webview自动登录(嵌入inappbrowser)。

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

应用程序启动,然后用户将被重定向到网站进行登录。但是用户必须一次又一次地输入他们的用户名和密码。有自动登录的可能性吗? Ive阅读关于localstorage。这是可能与外部网站上的inappbrowser(没有访问我知道的phonegap插件)。

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

推荐答案

应该是可能的。您只需要将正确的处理程序连接到 loadstop 事件,然后使用本地存储来存储用户名和密码,一旦提交被点击,如果已经存在,则自动填充。

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

这篇关于在外部网站上使用Inappbrowser自动登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆