FB评论“装载10个评论”按钮,点击通话应用程序窗口大小调整事件不工作

问题描述 投票:-1回答:1

我使用“https://developers.facebook.com/docs/plugins/comments/”的JavaScript SDK加载在我的应用程序的评论。现在我的问题是,我不能够跟踪评论iframe中负载更多的单击事件。我需要跟踪的功能设置父DIV的高度,每被点击加载更多的按钮事件后加载的意见DIV高度。

javascript facebook facebook-comments fbml
1个回答
0
投票

我试着用不同的解决方案和使用的“https://jsfiddle.net/vb4xgcmo/”提供的修改后的代码中发现一个工作样本。

window.fbAsyncInit = function () {
            FB.Event.subscribe( 'xfbml.render', function ( response ) {
                if ( $( '.fb-comments' ).length > 0 ) {
                    if ( $( '.fb-comments iframe' ).length > 0 ) {
                        iframeClickTracking( $( '.fb-comments iframe' ) );
                    }
                }
            } );
        }
        function iframeClickTracking( elm ) {
            elm.bind( 'mouseover', function () {
                console.log( 'in' );
                onIframeHeightChange( elm, function () {
                    $( '#section_1' ).css( 'height', $( '#fbv' ).height() );
                } );

            } );
            elm.bind( 'mouseout', function () {
                // If they leave the ad, then they aren't going to click. Kill the run event for resize.
                setTimeout( function () {
                    if ( elm.onIframeHeightChange ) {
                        $( '#section_1' ).css( 'height', $( '#fbv' ).height() );
                        clearTimeout( elm.onIframeHeightChange );
                    }
                }, 1000 );
            } );
        }

        function onIframeHeightChange( elm, callback ) {
            var lastHeight = elm.height(), newHeight;
            (function run() {
                newHeight = elm.height();
                if ( lastHeight != newHeight ) {
                    callback();
                }
                lastHeight = newHeight;
                if ( elm.onIframeHeightChange ) {
                    clearTimeout( elm.onIframeHeightChange );
                }
                elm.onIframeHeightChange = setTimeout( run, 1000 );
            })();
        }
© www.soinside.com 2019 - 2024. All rights reserved.