Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery-类似Facebook的按钮,异步脚本标记动态加载,未初始化两次_Jquery_Facebook_Asynchronous_Initialization - Fatal编程技术网

Jquery-类似Facebook的按钮,异步脚本标记动态加载,未初始化两次

Jquery-类似Facebook的按钮,异步脚本标记动态加载,未初始化两次,jquery,facebook,asynchronous,initialization,Jquery,Facebook,Asynchronous,Initialization,我正在使用Facebook上的异步脚本加载技术,将动态页面上的like按钮显示到加载了容器的ajax页面中。我第一次加载站点时,按钮将正确显示 。。但是,如果我用html(“”)从父容器中卸载页面,并以相同的方式再次加载它,则like按钮将不再初始化。Firebug向我显示脚本已加载到正确的div,但未执行 我像这样按住like按钮加载子页面(与ini和站点导航相同): like按钮的脚本如下所示: function showFBButton() { var html =

我正在使用Facebook上的异步脚本加载技术,将动态页面上的like按钮显示到加载了容器的ajax页面中。我第一次加载站点时,按钮将正确显示

。。但是,如果我用html(“”)从父容器中卸载页面,并以相同的方式再次加载它,则like按钮将不再初始化。Firebug向我显示脚本已加载到正确的div,但未执行

我像这样按住like按钮加载子页面(与ini和站点导航相同):

like按钮的脚本如下所示:

function showFBButton() {
    var html =
        '<div id="fb-button">'
        + '<div class="fb-like" data-href="https://www.facebook.com/xxx" data-send="false" data-layout="button_count" data-width="70" data-show-faces="false" data-action="like"></div>'
        + '<div id="fb-root"></div>'
        + '</div>';
    $('#fb-viewport').html(html);
    window.setTimeout( function () {
        var e = document.createElement( 'script' );
        e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/'+fblang+'/all.js#'+Math.random()+'&xfbml=1&appId=xxx';
        document.getElementById( 'fb-root' ).appendChild( e );
        document.getElementById( 'fb-button' ).removeAttribute( 'class' );
    }, 2000 );
return true;
};
函数showFBButton(){
变量html=
''
+ ''
+ ''
+ '';
$('#fb viewport').html(html);
setTimeout(函数(){
var e=document.createElement('script');
e、 异步=真;
e、 src=document.location.protocol++'//connect.facebook.net/'+fblang++'/all.js#'+Math.random()++'&xfbml=1&appId=xxx';
document.getElementById('fb root').appendChild(e);
getElementById('fb button')。removeAttribute('class');
}, 2000 );
返回true;
};
为什么当我从每个导航站点之间的中间加载holdslikebutton.php时脚本没有初始化。我需要做些什么来触发all.js的执行吗?但为什么它要用浏览器url或浏览器重新加载从外部加载站点呢


这并不复杂。也许我监督了什么?我被困住了,我很乐意知道如何解决这个问题。

只有在SDK初始化时,才会对DOM中的元素呈现FB插件

要重新解析DOM(或其部分)以获得新的插件标记,需要使用


(之前在这里讨论过多次…

谢谢。使用FB-API重新解析是解决方案。下次我会更好地使用搜索引擎!
function showFBButton() {
    var html =
        '<div id="fb-button">'
        + '<div class="fb-like" data-href="https://www.facebook.com/xxx" data-send="false" data-layout="button_count" data-width="70" data-show-faces="false" data-action="like"></div>'
        + '<div id="fb-root"></div>'
        + '</div>';
    $('#fb-viewport').html(html);
    window.setTimeout( function () {
        var e = document.createElement( 'script' );
        e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/'+fblang+'/all.js#'+Math.random()+'&xfbml=1&appId=xxx';
        document.getElementById( 'fb-root' ).appendChild( e );
        document.getElementById( 'fb-button' ).removeAttribute( 'class' );
    }, 2000 );
return true;
};