Facebook标签不再调整大小

时间:2013-08-28 15:28:58

标签: javascript facebook facebook-graph-api tabs facebook-javascript-sdk

有没有人知道调整facebook标签的iframe大小的代码最近是否已经显示?

我曾经在头脑中添加这个:

<script type="text/javascript">
window.fbAsyncInit = function() 
{ 
   FB.Canvas.setSize( {height: 1040} );
}

// Do things that will sometimes call sizeChangeCallback()
function sizeChangeCallback() 
{
    FB.Canvas.setSize( {height: 1040} );
}
</script>

并在体内:

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
   FB.init({
      appId : '561492603881225',
      status : true, // check login stat
      cookie : true, // enable cookies to allow the server to access the session
      xfbml : true // parse XFBML 
});
</script>

所有需要更改的是APP ID和setSize脚本中的值,然后我可以设置高度以匹配每个选项卡上的内容。

然而,现在查看我的标签,他们似乎已经重置回默认的800px高,这让我觉得facebook已经改变了他们做事的方式,但在任何地方找不到任何东西,在开发者博客上什么都看不见

2 个答案:

答案 0 :(得分:0)

首先必须检查Canvas是否已加载 -

FB.Canvas.setDoneLoading( function(response) {
    console.log(response.time_delta_ms);
    FB.Canvas.setAutoGrow();
});

FB.Canvas.setDoneLoading

或者,您也可以尝试onBodyLoad

答案 1 :(得分:0)

这似乎无法设置高度,可能是一个响应式解决方案吗?

<div id="fb-root"></div>
<script type="text/javascript">
fb_root = document.createElement( 'div' );
fb_root.id = 'fb-root';
try
{
window.document.childNodes[0].appendChild( fb_root );
}
catch( error )
{
window.document.body.appendChild( fb_root );
}

window.fbAsyncInit = function() {
FB.init({
appId  : '1375967019301812', //your app ID
status : true, // check login status
cookie : true // enable cookies to allow the server to access the session
});

//FB.Canvas.setSize({ width: 520, height: 1400 });

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

var mySetSize = function() {
    var height = getDocHeight();
    FB.Canvas.setSize({ width: 520, height: height });
    setTimeout( mySetSize, 200 );
};
setTimeout( mySetSize, 200 );
};

(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
  '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());


var head = document.getElementsByTagName('head')[0],
style = document.createElement('style'),
rules = document.createTextNode('body { position: relative; max-width:     520px!important;width: 520px!important; overflow: hidden!important; margin: 0px!important;     }');

style.type = 'text/css';
if(style.styleSheet)
style.styleSheet.cssText = rules.nodeValue;
else style.appendChild(rules);
head.appendChild(style);

</script>