防止自己的网页被iframe框架引用(X-Frame-Options)
2011-10-20 06:57
621 查看
防止自己的网页被iframe框架引用
frame框架, 前端安全我要评论
March 15, 2011
前端开发与脚本
对于一些安全要求较高的网站,往往不希望自己的网页被另外非授权网站框架包含,因为这往往是危险的,因为不法分子总是想尽办法以“钓鱼”的方式牟利。
对于禁止网页被frame或者iframe框架,我总结了下面三种方法供大家参考。
1.使用meta元标签
1 2 3 4 5 6 | <html> <head> <meta http-equiv="Windows-Target" contect="_top"> </head> <body></body> </html> |
2.使用JavaScript脚本
1 2 3 4 5 67 | function location_top(){ if(top.location!=self.location){ top.location=self.location; return false; } return true; } location_top(); // 调用 |
3.使用HTTP响应头
这里介绍的响应头是X-Frame-Options,这个属性可以解决使用js判断会被var location;破解的问题,IE8、Firefox3.6、Chrome4以上的版本均能很好的支持,关于这个响应头属性详细的介绍可以看《The X-Frame-Options response header》
,这篇文章给出了这个属性两个可能的值:
DENY The page cannot be displayed in a frame, regardless of the site attempting to do so.
SAMEORIGIN The page can only be displayed in a frame on the same origin as the page itself.
SAMEORIGIN The page can only be displayed in a frame on the same origin as the page itself.
其中我们用到DENY,这样就禁止该页在上述支持的浏览器被框架引用了。当然设置header响应头的办法有很多,比如PHP的header函数和.htaccess的Header set等。
相关文章推荐
- X-Frame-Options头未设置 防止网页被iframe内框架调用
- HTTP X-Frame-Options 防止iframe内框架调用
- X-Frame-Options防止网页放在iframe中
- 防止别人用IFRAME框架嵌套调用自己网页的方FA
- HTTP X-Frame-Options 防止iframe内框架调用
- X-Frame-Options防止网页放在iframe中
- js如何判断是否在iframe中及防止网页被别站用 iframe嵌套 (Load denied by X-Frame-Options)
- 防止别人用IFRAME框架嵌套调用自己网页的方法
- 关于防止自己网页内容被别人iframe的问题
- 使用X-Frame-Options防止网页被Frame
- 关于防止自己网页内容被别人iframe的问题
- 几种location.href的区别 js实现网页防止被iframe框架嵌套功能 .
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- 几种location.href的区别 js实现网页防止被iframe框架嵌套功能
- iis、apache、nginx使用X-Frame-Options防止网页被Frame的解决方法
- 使用 X-Frame-Options 防止被iframe 造成跨域iframe 提交挂掉
- 使用设置报头x-Frame-Options限制iframe网页嵌套
- js实现网页防止被iframe框架嵌套及几种location.href的区别