[英]How do I detect that facebook app is loading page to change CSS?
Facebook iframes are 758px wide. Facebook iframe的宽度为758px。 The website is 900px wide.
该网站的宽度为900px。
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? 有没有办法告诉我apps.facebook.com正在拉入页面,以便我可以更改样式以使页面更窄?
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. 当应用加载到Facebook iframe中时,如果您的页面宽于facebook的标准iframe宽度(758px?),则您的页面将挂在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. 我上面的回答肯定会检测到您正在加载我的Facebook应用程序(假设它是http://apps.facebook.com/forwardmyinfo/ ),但仅在您的目标网页上。 Once you click within the site - which is all an app really is, it sees the referrer as being the site...not facebook.
一旦您在站点内单击-这实际上就是一个应用程序,它会将引荐来源网址视为站点...而不是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. 别忘了,您还将在每个页面上都需要session_start()。
Hope that helps someone. 希望能对某人有所帮助。
ifaour's ssuggestion of: ifaour的建议:
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.
它确实需要进行测试,但是我对结果感到满意。
There's the complicated way, and the easy way. 有复杂的方法,也有简单的方法。
The easy way is simply tell your page the link comes from facebook by giving facebook a unique URL. 简单的方法是,通过为Facebook提供唯一的网址来告诉您的页面链接来自facebook。
http://server/page?source=Facebook
Then check your _GET
scope. 然后检查您的
_GET
范围。
That's also going to help with logging. 这也将有助于日志记录。
A simple and reliable way would be to set an get parameter. 一种简单可靠的方法是设置get参数。 If the url of your page is
如果您的页面网址是
htttp://whatever.com/page.php
Make facebook link to 使facebook链接到
htttp://whatever.com/page.php?ref=facebook
On session start you can test if this was set. 在会话开始时,您可以测试是否已设置。
if(@$_GET['ref']){
if($_GET['ref']=='facebook'){
//change display
}
}
Using a relative layout without fixed pixel size would be the better option. 使用没有固定像素大小的相对布局是更好的选择。
Or use the standard way of doing this! 或使用标准方法执行此操作!
Facebook will always send you the signed_request
: Facebook将始终向您发送
signed_request
:
if( isset($_REQUEST['signed_request']) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.