网页被他人嵌套,可能会引起一些问题,html
前端检测 top 窗口是否就是 self ,前端
try{ top.location.hostname; if (top.location.hostname != window.location.hostname) { top.location.href =window.location.href; } } catch(e){ top.location.href = window.location.href; }
在后端项目的 .htaccess 文件中使用 X-Frame-Options 的 SAMEORIGIN 参数后端
<ifModule mod_headers.c> Header always append X-Frame-Options SAMEORIGIN </ifModule>
备注
X-Frame-Options 有三个选项:
DENY:表示该页面不容许在 frame 中展现,即使是在相同域名的页面中嵌套也不容许。
SAMEORIGIN:表示该页面能够在相同域名页面的 frame 中展现。
ALLOW-FROM uri:表示该页面能够在指定来源的 frame 中展现。app
通常使用 SAMEORIGIN 容许同域嵌套。网站
具体配置可参考: http://www.javashuo.com/article/p-uqnfudmi-eg.htmlcode
我通常会喜欢后端部署文件配置,很是简便,整站生效。htm