duanhuang4306 2011-04-04 06:53
浏览 45
已采纳

如何检测Facebook应用程序正在加载页面以更改CSS?

Facebook iframes are 758px wide. The website is 900px wide.

Is there any way to tell that apps.facebook.com is pulling in the page so I can change the styles to make the page narrower?

  • 写回答

4条回答 默认 最新

  • duanjia4097 2011-04-04 07:15
    关注
    if($_SERVER['HTTP_REFERER'] == "http://apps.facebook.com/forwardmyinfo/"){
        do something
    }
    

    EDIT:

    So here is the problem fleshed out a bit more (which I discovered later) and the solution.

    When an app is loaded into the facebook iframe if your page is wider than facebook's standard iframe width (758px?) your page is going to hang off the right of the iframe.

    My answer above will most certainly detect that you are loading my facebook app (assuming it is http://apps.facebook.com/forwardmyinfo/), but only on your landing page. Once you click within the site - which is all an app really is, it sees the referrer as being the site...not facebook.

    My solution was on loading the home page to change the style sheet, but more importantly, set a session variable that can be tested on other pages:

    if($_SERVER['HTTP_REFERER'] == "http://apps.facebook.com/forwardmyinfo/"){
        echo '<link href="includes/facebook.css" rel="stylesheet" type="text/css" media="Screen"/>';
        $_SESSION["FB"] = true;
        //do other stuff if needed
    }
    else{
        //load original style sheet or whatever
    }
    

    The rest is obvious, but here it is anyway:

    On every other page include this code:

    if($_SESSION["FB"]){
        echo '<link href="includes/facebook.css" rel="stylesheet" type="text/css" media="Screen"/>';
        //do other stuff if needed
    }
    else{
        //load original style sheet
    }
    

    Don't forget you are also going to need session_start() on each page.

    Hope that helps someone.

    ifaour's ssuggestion of:

    if( isset($_REQUEST['signed_request']) )
    

    may also work, but I am not sure if the variable is passed from page to page so it wouldn't carry through the site. It does warrant testing for sure, but I am happy with my result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计