Furkan Gözükara
Furkan Gözükara

Reputation: 23840

How to understand your pages are being requested under facebook or not inside masterpage asp.net

I am going to add my website to the facebook as an application. Facebook do not allow 3 rd party ads so i have to remove them. I want to remove ads for only facebook visitors. So i want to understand whether page is being called under facebook as an iframe or not. How can i do that with javascript ? Thank you.

I can also use jquery.

asp.net 4.0

Upvotes: 1

Views: 159

Answers (1)

CdB
CdB

Reputation: 4908

The following detects if your page is viewed in an iframe:

if (window.location != window.parent.location){
      //you are in an iframe
}
else {
      //you are NOT in an iframe
}

[EDIT]
If you want also to specify that the iframe is in facebook then you could try this:

if(window.name != "") {
  //We are on Facebook
} 
else
{
  //We are just in the normal browser window
}

I haven't tested this, just came across a few weeks ago here

Upvotes: 1

Related Questions