Facebook页面嵌入响应 - 以前的帖子解决方案不起作用

时间:2016-04-14 05:15:34

标签: javascript facebook iframe

- UPDATE-- 这是我对这个问题的解决方案。很奇怪我无法在facebook插件中使用javascript变量来获得宽度和高度,以便每次都能产生完美的效果。我只是将插件的高度和宽度设置为非常高的值,使其适合,令人惊讶的是没有裁剪。我有一个延迟函数,在调整大小以重新加载插件后触发。这种方法唯一的缺点是滚动条看起来有点滑稽,因为插件的高度和宽度设置得很高。

$

- 下面的原帖 -

我正在努力使facebook页面嵌入响应。我已经尝试过每一个该死的方式,我不明白为什么这不起作用。页面正在加载为wordpress页面模板。

我现在使用的主要方法是在页面加载后添加插件以动态获取高度和宽度的大小,然后将其添加到文档并解析。很遗憾,解析时没有任何内容。我在控制台中检查DOM,元素就在那里。

\b

1 个答案:

答案 0 :(得分:0)

我有同样的问题,我希望在桌面上嵌入一个大(宽度:500px),在移动设备上嵌入一个小(宽度:350px)。我有解决方案,这就是我使用的:

javascript:

<script language="JavaScript">
function autoResizeManual(id, newwidth, newheight ){

    document.getElementById(id).width = (newwidth) + "px";
    document.getElementById(id).height = (newheight) + "px";

}
//-->
</script>

然后PHP - 有两种情况 - 对于常规帖子,FB的默认宽度为500px,视频为560px。

 if($deviceType != 'computer') { //check if it's a mobile any way you want
    if(stripos($my_embed,"<iframe") !== false) { 
//check if the fb frame is prezent in the embed

            if(stripos($my_embed,"&width=500") !== false) {
//if it's a regular post
                $embed_width = '320';
                $embed_height = '500';
                $my_embed = str_ireplace('&width=500', '&width=320', $my_embed);
            }

if(stripos($my_embed,"&width=560") !== false) {

//if it's a video
                $embed_width = '320';
                $embed_height = '200';
                $my_embed = str_ireplace('&width=560', '&width=320', $my_embed);
            }

                $change_petition = '<iframe id="iframe1" onLoad="autoResizeManual(\'iframe1\',\''.$embed_width.'\',\''.$embed_height.'\');" ';

//code to be injected to launch the javascript

                $my_embed=  str_ireplace('<iframe', $change_petition, $my_embed);

//the injection

    }
    }

print $my_embed
相关问题