如何禁用Google Signin按钮个性化,固定显示“Sign In With Google”
问题
我在项目中添加了一个“Sign In With Google”按钮,代码如下:
<script src="https://accounts.google.com/gsi/client"></script> <script type="text/javascript"> window.onload = function () { google.accounts.id.initialize({ client_id: "client_id_here", callback: handleCredentialResponse }); google.accounts.id.renderButton( document.getElementById("googleButtonDiv"), { theme: "outline", size: "large" } // customization attributes ); google.accounts.id.prompt(); // also display the One Tap dialog } </script>
该按钮功能正常,但当用户有活跃Google账号时,按钮会显示‘Sign In As name’,我的客户不希望出现这种情况。请问如何禁用该个性化显示,让按钮始终显示文本“Sign In With Google”?
解决方案
在google.accounts.id.renderButton的配置对象中添加text: "signin_with"参数,即可强制按钮始终显示固定文本“Sign In With Google”,不会根据用户账号个性化调整。
修改后的完整代码如下:
<script src="https://accounts.google.com/gsi/client"></script> <script type="text/javascript"> window.onload = function () { google.accounts.id.initialize({ client_id: "client_id_here", callback: handleCredentialResponse }); google.accounts.id.renderButton( document.getElementById("googleButtonDiv"), { theme: "outline", size: "large", text: "signin_with" // 强制固定按钮文本 } ); google.accounts.id.prompt(); // also display the One Tap dialog } </script>
这个参数会覆盖Google默认的个性化文本逻辑,无论用户是否有活跃账号,按钮都会保持统一的显示内容。
内容的提问来源于stack exchange,提问作者sveti petar
相关产品推荐
相关产品推荐

