【问题标题】:facebook tab not resizing any morefacebook标签不再调整大小
【发布时间】:2013-08-28 15:28:57
【问题描述】:

有谁知道调整 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 脚本中的值,然后我可以设置高度以匹配每个选项卡上的内容。

但是现在看我的标签,所有标签似乎都重置为默认的 800 像素高,这让我觉得 Facebook 已经改变了他们做事的方式,但在任何地方都找不到任何东西,并且在开发者博客上什么也没看到.

【问题讨论】:

  • 我使用下面的“FB.Canvas.setAutoGrow();” ??
  • 我也读过,但它从来没有对我有用,所以 setsize 对我来说总是没问题的。刚刚尝试用 setAutogrow 替换它但没有运气??

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


【解决方案1】:

你首先要检查 Canvas 是否被加载-

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

FB.Canvas.setDoneLoading

或者,你也可以试试onBodyLoad

【讨论】:

  • 这是否会在头部其他脚本之前进入脚本标签?
  • FB.init()之后使用这个
【解决方案2】:

这似乎可以在没有设置高度的情况下工作,可能是响应式解决方案?

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多