Javascript 谷歌使用自定义文本登录网站
我已经按照谷歌官方教程为我的网站实现了谷歌登录: 使用上面的教程,我得到以下按钮 现在我正试图将按钮的文本从“登录”更改为“与谷歌连接”,但什么也没有发生 我的Javascript代码Javascript 谷歌使用自定义文本登录网站,javascript,jquery,google-oauth,google-signin,Javascript,Jquery,Google Oauth,Google Signin,我已经按照谷歌官方教程为我的网站实现了谷歌登录: 使用上面的教程,我得到以下按钮 现在我正试图将按钮的文本从“登录”更改为“与谷歌连接”,但什么也没有发生 我的Javascript代码 function onSignIn(googleUser) { var profile = googleUser.getBasicProfile(); loginpassword = profile.getId();
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>
与谷歌连接
你知道怎么修改课文吗?尽管我提供了客户端ID和platform.js文件的外部链接,但它仍然不起作用。请帮助。谷歌的platform.js库正在呈现按钮和文本 为了覆盖它,您需要。以谷歌为例:
<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>
请注意,您必须遵守。或者您可以更改使用Javascript生成的跨度文本,请尝试以下操作 将代码中的Div id替换为“DivID”
setTimeout(函数(){
$('#DivID div:last').text(“向谷歌注册”);
$('#DivID div:first').text(“向谷歌注册”);
}, 3000);代码>用于HTML部分,例如,我们有:
<div id="GoogeSigninButton" data-onsuccess="onSignIn" class="g-signin2"></div>
对于按钮代码后的脚本标记,如下所示:
<script>
setTimeout(function () {
$('#GoogeSigninButton div div span span:last').text("Custom Sign in Text");
$('#GoogeSigninButton div div span span:first').text("Custom Sign in Text");
$('#GoogeSigninButton div div span span:last').css("font-family", "Arial");//for font formatting
$('#GoogeSigninButton div div span span:first').css("font-family", "Arial");//for font formatting
}, 10000);
</script>
setTimeout(函数(){
$('#GoogeSigninButton div div span:last')。文本(“自定义登录文本”);
$('#GoogeSigninButton div div span:first')。文本(“自定义登录文本”);
$('#GoogeSigninButton div span:last').css(“字体系列”,“Arial”);//用于字体格式
$('#GoogeSigninButton div span:first').css(“字体系列”,“Arial”);//用于字体格式
}, 10000);
它将使按钮的文本在页面加载10秒左右后变成您所需的自定义文本和自定义字体。这主要起作用,但他们的示例并不完整,因为谷歌图标URL是相对于网页服务器的URI。当图标存在时,从Google开发者的网站上提供该示例是有效的,但是默认情况下,任何在自己的服务器上测试该图标的人都不会使用该示例。谷歌的带有品牌内容的zip不包含图标,也没有讨论从何处获取官方图标。@Nick我已编辑以澄清谷歌示例代码中包含的示例URL必须指向有效的图像文件。来自谷歌的图标示例。谢谢,不要打击你的例子,因为谷歌的文档在这里失败了,只是把图标作为例子的一部分,而不是在任何官方位置。希望他们为完整的按钮渲染提供一个类似于zip的图标集,但到目前为止运气不好。@Nick Yeah,他们的品牌文件,以及制作自己的品牌指南的措辞,非常令人困惑。您不能更改图标的大小,但是如果您想创建不同大小的自定义图标,请使用示例大小。。。呵呵?
<script>
setTimeout(function () {
$('#GoogeSigninButton div div span span:last').text("Custom Sign in Text");
$('#GoogeSigninButton div div span span:first').text("Custom Sign in Text");
$('#GoogeSigninButton div div span span:last').css("font-family", "Arial");//for font formatting
$('#GoogeSigninButton div div span span:first').css("font-family", "Arial");//for font formatting
}, 10000);
</script>