一、如果对方是静态调用 iframe,用 js 阻止即可,
<script>
if ( top !== self ) top.location.replace( self.location.href );
</script>
二、如果对方是动态调用的(类似于下方代码),又禁用了自己页面的 js 的话,
<script type="text/javascript" charset="utf-8">
document.write('<iframe seamless sandbox security="restricted" id="url_mainframe" frameborder="0" scrolling="yes" name="main" src="http://www.mypage.com/this.html" style="height:100%; visibility: inherit; width: 100%; z-index: 1;overflow: visible;"></iframe>');
</script>
可在 php 文件里加上 X-Frame-Options 响应头代码
header('X-Frame-Options:Deny');
X-Frame-Options 有三个值
分别是 “DENY”、“SAMEORIGIN”、“ALLOW-FROM http://domain.com/url.html”
DENY:表示该页面禁止 frame,即使是同域名的页面中嵌套也不允许。 SAMEORIGIN:表示该页面可以在同域名页面的 frame 中展示。 ALLOW-FROM url:表示该页面可以在指定来源的 frame 中展示。
三、踩坑!下面这种直接在 html 的 head 中加 meta 是没用的,切记。
<meta http-equiv="X-Frame-Options" content="deny">
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有