javascript - Facebook fbAsyncInit not loading when all.js loaded before -
i built module displays fb button on site. works fine excepting when there <script src="https://connect.facebook.net/en_us/all.js"></script>
loaded before on same page. if all.js loaded before, fbasynciniti never triggered.
my code:
<div id="fb-root"></div> <li class="fblike"> <div data-share="false" data-show-faces="false" data-layout="box_count" data-href="<?php echo $share_url?>" data-action="like" class="fb-like"></div> </li> <script> window.fbasyncinit = function() { fb.init({ appid : 'app_id', xfbml : true, version : 'v2.1' }); }; (function(d, s, id){ var js, fjs = d.getelementsbytagname(s)[0]; if (d.getelementbyid(id)) {return;} js = d.createelement(s); js.id = id; js.src = "//connect.facebook.net/en_us/sdk.js"; fjs.parentnode.insertbefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script>
it work if remove window.fbasyncinit = function() {
code. not solution because don't know if customer have all.js loaded before or not. check jquery if script inside dom, still not proper solution because script can inside dom not loaded yet.
what proper method check if all.js loaded before can remove window.fbasyncinit = function() {
in such case? or there other solution?
Comments
Post a Comment