1、在响应头里加一个X-Frame-Options
其取值有三种,大部分浏览器都支持:
DENY:浏览器拒绝当前页面加载任何Frame页面
SAMEORIGIN:frame页面的地址只能为同源域名下的页面
ALLOW-FROM origin:origin为允许frame加载的页面地址
这样被不同源的页面以iframe包含时就不会显示了
设置方法:
2、js脚本法:
在自己的页面中写入如下js脚本中的一个即可:
if (window != window.top) {
window.top.location.replace(window.location)
// 这是直接代替外窗,你也可以干别的
}
if (top != self) {
top.location = self.location;
}
if (self == top) {
var theBody = document.getElementsByTagName('body')[0];
theBody.style.display = "block";
} else {
top.location = self.location;
}