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.com") !== -1;
}
return false;
}
if (!referrerIsFacebookApp()) {
top.location.replace("https://www.facebook.com/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?
Use 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.com/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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With