如何防止我的网站页面通过 iFrame 的第 3 方网站框架加载 [英] How to prevent my site page to be loaded via 3rd party site frame of iFrame

查看:16
本文介绍了如何防止我的网站页面通过 iFrame 的第 3 方网站框架加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在页面加载期间发现我的页面作为框架嵌入到其他站点?我猜推荐人请求标头在这里帮不了我?谢谢.

How can I find out that my page is embedded as a frame to other site during page loading? I guess referrer request header can't help me here? Thanks.

推荐答案

你不能从服务器端检查它,但你可以在页面加载后使用 javascript 来检测它.比较topself,如果它们不相同,你就在一个框架中.

You cannot check it from the server's side, but you can use javascript to detect it after the page has loaded. Compare top and self, if they're not identical, you are in a frame.

此外,一些现代浏览器尊重 X-FRAME-OPTIONS 标头,它可以有两个值:

Additionally, some modern browsers respect the X-FRAME-OPTIONS header, that can have two values:

  • DENY - 如果页面包含在框架中,则防止页面被呈现
  • SAMEORIGIN – 与上述相同,除非页面与顶级框架集持有者属于同一域.

用户包括无法嵌入框架的 Google 的 Picasa.

Users include Google's Picasa, that cannot be embedded in a frame.

支持header的浏览器,最低版本:

Browsers that support the header, with the minimum version:

  • IE8 和 IE9
  • Opera 10.50
  • Safari 4
  • Chrome 4.1.249.1042
  • Firefox 3.6.9(带有 NoScript 的旧版本)
  • IE8 and IE9
  • Opera 10.50
  • Safari 4
  • Chrome 4.1.249.1042
  • Firefox 3.6.9 (older versions with NoScript)

这篇关于如何防止我的网站页面通过 iFrame 的第 3 方网站框架加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆