禁止网站被别人通过 iframe 引用
前端处理
方案一:js方法
不可靠,不推荐使用
<script type="text/javascript">
if(self != top) { top.location = self.location; }
</script>
把上面的JS代码片段放到你页面的 head 中即可。
方案二:Meta标签方法
<meta http-equiv="X-FRAME-OPTIONS" content="DENY">
以上两种为前端处理方法。
后端程序处理
方案三:PHP方法
<?php header(‘X-Frame-Options:Deny'); ?>
以上是后端程序处理方法。
服务器端处理
方案四:Apache主机方法
Header always append X-Frame-Options SAMEORIGIN
方案五:Nginx主机方法
add_header X-Frame-Options "SAMEORIGIN";
方案六:.htaccess方法
在网站根目录下的.htaccess文件中中加上以下内容
Header append X-FRAME-OPTIONS "SAMEORIGIN"
方案七:IIS方法
在web.config文件中加上以下内容
<system.webServer>
...
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
...
</system.webServer>
以上四种解决方案为服务器端处理方案。
https://blog.csdn.net/dugujiancheng/article/details/51669164