i want to redirect all traffic going to my Facebook app tab on my server directly to my Facebook app. Therefore I check with the following code if the user is inside the Facebook iframe or on my webpage:
<!-- language: lang-js -->
function referrerIsFacebookApp() {
if(document.referrer) {
return document.referrer.indexOf("facebook") !== -1;
}
return false;
}
if (!referrerIsFacebookApp()) {
top.location.replace("");
};
If I open up the page with the browser everything works as it should. But if I link to this page and open the link the redirect doesnt work. Any hints?
i want to redirect all traffic going to my Facebook app tab on my server directly to my Facebook app. Therefore I check with the following code if the user is inside the Facebook iframe or on my webpage:
<!-- language: lang-js -->
function referrerIsFacebookApp() {
if(document.referrer) {
return document.referrer.indexOf("facebook.") !== -1;
}
return false;
}
if (!referrerIsFacebookApp()) {
top.location.replace("https://www.facebook./bommelME/app_264697733636385");
};
If I open up the page with the browser everything works as it should. But if I link to this page and open the link the redirect doesnt work. Any hints?
Share Improve this question edited Jul 21, 2012 at 9:53 Teun Zengerink 4,4035 gold badges32 silver badges32 bronze badges asked Jul 20, 2012 at 14:28 fourgoodfourgood 1873 silver badges15 bronze badges 2-
it depends on what is inside your
referrerIsFacebookApp
function – haynar Commented Jul 20, 2012 at 14:31 - sry, i just edited the code. pasted the wrong one ;) – fourgood Commented Jul 20, 2012 at 14:34
2 Answers
Reset to default 7Use window.top to detect whether your app is in an iFrame or not. Try this.
if (window!=window.top) {
/* I'm in a frame! */
window.location = "https://www.facebook./bommelME/app_264697733636385";
}
Cheers.
I think you should check the window.parent
object instead of document.referrer
, because the page can be referenced from another one as you've said but not being included via iframe