admin管理员组文章数量:1316688
I'm trying to add a google sign-in button in a hybrid app. It renders correctly when the button
<div class="g-signin2" data-onsuccess="onSignIn"></div>
is in the initial page, but when the page is not the first to be loaded (btw pages are loaded via ajax) somehow the button fails to render. For more information i'm using Framework7 but i don't believe the issue is related to the framework but to my faulty logic. I'm following the instructions form google developers.
I'm trying to add a google sign-in button in a hybrid app. It renders correctly when the button
<div class="g-signin2" data-onsuccess="onSignIn"></div>
is in the initial page, but when the page is not the first to be loaded (btw pages are loaded via ajax) somehow the button fails to render. For more information i'm using Framework7 but i don't believe the issue is related to the framework but to my faulty logic. I'm following the instructions form google developers.
Share Improve this question asked Nov 16, 2015 at 12:09 vhoxhavhoxha 602 silver badges10 bronze badges 1- 2 Just include 'apis.google./js/platform.js' script after your ajax call is plete. – Valentin Podkamennyi Commented Nov 17, 2015 at 12:45
3 Answers
Reset to default 4It doesn't work when the div element is loaded dynamically because the Google Sign-In script looks up the tag with the g-signin2
-class upon execution, which it won't find since it isn't loaded into the DOM tree yet.
Instead, you can use the gapi.signin2.render
function to render the button after your AJAX call is pleted. For example, if your placeholder tag is has the id div_tag_id
, in JavaScript:
gapi.signin2.render("div_tag_id", {
"scope": "profile email openid",
"width": 200,
"height": 40,
"longtitle": true,
"theme": "dark",
"onsuccess": function (googleUser) {
// Called when the user signs in
},
"onfailure": function (e) {
console.warn("Google Sign-In failure: " + e.error);
}
});
- Reference
You can use onPageInit
as described in Framework7 documentation:
myApp.onPageInit(pageName, function(page) {
var script = document.createElement('script');
script.src = 'https://apis.google./js/platform.js';
document.body.appendChild(script);
});
With google Chrome in incognito mode, you’re going to get that this works
本文标签: javascriptGoogle signin button does not render when containing is loaded via ajaxStack Overflow
版权声明:本文标题:javascript - Google sign-in button does not render when containing is loaded via ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742005377a2411848.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论