如何了解您的页面是在 facebook 下被请求还是不在 masterpage asp.net 内被请求

发布于 2024-12-19 14:54:00 字数 190 浏览 1 评论 0原文

我将把我的网站作为应用程序添加到 Facebook。 Facebook 不允许第三方广告,所以我必须删除它们。我想删除仅针对 Facebook 访问者的广告。所以我想了解页面是否在 facebook 下作为 iframe 被调用。我怎样才能用javascript做到这一点?谢谢。

我也可以使用jquery。

ASP.NET 4.0

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春如此纠结 2024-12-26 14:54:00

以下代码检测您的页面是否在 iframe 中查看:

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

[编辑]
如果您还想指定 iframe 位于 facebook 中,那么您可以尝试以下操作:

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

我还没有测试过这个,只是几周前遇到的 此处

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文