gpt4 book ai didi

javascript - Google 使用自定义文本登录网站

转载 作者:搜寻专家 更新时间:2023-11-01 05:29:45 24 4
gpt4 key购买 nike

我按照谷歌的官方教程为我的网站实现了谷歌登录: https://developers.google.com/identity/sign-in/web/sign-in

使用上面的教程我得到以下按钮

Google signin

现在我正在尝试将按钮的文本从“登录”更改为“与 Google 连接”,但没有任何反应..

我的 Javascript 代码..

           function onSignIn(googleUser) {

var profile = googleUser.getBasicProfile();
loginpassword = profile.getId();
loginemail = profile.getEmail();
};

HTML 代码..

     <div class="g-signin2" data-onsuccess="onSignIn">Connect with Google</div>

知道如何更改文本吗?即使我提供了 platform.js 文件的客户端 ID 和外部链接,它仍然无法正常工作..请帮助..

最佳答案

来自 google 的 platform.js 库正在呈现按钮以及文本。

为了覆盖它,您需要 build your own custom button .来自谷歌的例子:

<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
<script src="https://apis.google.com/js/api:client.js"></script>
<script>
var googleUser = {};
var startApp = function() {
gapi.load('auth2', function(){
// Retrieve the singleton for the GoogleAuth library and set up the client.
auth2 = gapi.auth2.init({
client_id: 'YOUR_CLIENT_ID.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
// Request scopes in addition to 'profile' and 'email'
//scope: 'additional_scope'
});
attachSignin(document.getElementById('customBtn'));
});
};

function attachSignin(element) {
console.log(element.id);
auth2.attachClickHandler(element, {},
function(googleUser) {
document.getElementById('name').innerText = "Signed in: " +
googleUser.getBasicProfile().getName();
}, function(error) {
alert(JSON.stringify(error, undefined, 2));
});
}
</script>
<style type="text/css">
#customBtn {
display: inline-block;
background: #4285f4;
color: white;
width: 190px;
border-radius: 5px;
white-space: nowrap;
}
#customBtn:hover {
cursor: pointer;
}
span.label {
font-weight: bold;
}
span.icon {
background: url('{{path to your button image}}') transparent 5px 50% no-repeat;
display: inline-block;
vertical-align: middle;
width: 42px;
height: 42px;
border-right: #2265d4 1px solid;
}
span.buttonText {
display: inline-block;
vertical-align: middle;
padding-left: 42px;
padding-right: 42px;
font-size: 14px;
font-weight: bold;
/* Use the Roboto font that is loaded in the <head> */
font-family: 'Roboto', sans-serif;
}
</style>
</head>

请注意,您可以找到实际的图标文件 on Google's server for download .

设置样式和 Javascript 后,您可以通过 HTML 调用按钮本身,此时您可以指定文本:

  <body>
<!-- In the callback, you would hide the gSignInWrapper element on a
successful sign in -->
<div id="gSignInWrapper">
<span class="label">Sign in with:</span>
<div id="customBtn" class="customGPlusSignIn">
<span class="icon"></span>
<span class="buttonText">Google</span>
</div>
</div>
<div id="name"></div>
<script>startApp();</script>
</body>
</html>

注意必须遵守Google's branding guidelines .

关于javascript - Google 使用自定义文本登录网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34677954/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com