您好,我正在使用 google api 登录我的网络应用程序。现在它工作正常。但问题是 sigin 在我进入登录页面时自动启动。但我不想那样。我希望用户首先单击登录按钮,然后该过程将开始。
我正在使用下面的按钮
<div class="g-signin2" data-onsuccess="onSignIn"></div>
和google log in引用 。
最佳答案
使用“attachClickHandler”启动 Google 登录。
<script src="https://apis.google.com/js/client:platform.js?onload=init" async defer></script>
<script>
function init() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: '*************.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
scope: 'profile email'
});
element = document.getElementById('glogin');
auth2.attachClickHandler(element, {}, onSignUp, onFailure);
});
}
function onSignUp(googleUser) {
var profile = googleUser.getBasicProfile();
}
</script>
关于javascript - 单击按钮启动 Google 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32624007/