Refused to display 'http://www.***.com/login/doLogin.html' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. 

触发原因:页面的返回头被设置 X-Frame-Options SAMEORIGIN ,只能被同源的iframe 引用。跨域名的iframe 没法显示了。

解决办法:
第一步 把 服务器上的 X-Frame-Options header 去掉

第二步 添加 如下代码到 不想被iframe 的页面header 里去。
<style id="antiClickjack">body{display:none !important;}</style>
<script>
if (self === top) {
var antiClickjack = document.getElementById("antiClickjack");
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
}
</script>

其他:

X-Frame-Options ALLOW-FROM 只支持单一域名 想支持多个二级域名的这个无解

并不是所有的浏览器都支持  这个header 所以,低版本的浏览器仍然会被iframe 成功

参考:http://www.css88.com/archives/5141

Browsers Supporting X-Frame-Options  
http://blogs.msdn.com/b/ieinternals/archive/2010/03/30/combating-clickjacking-with-x-frame-options.aspx

无法通过 <meta http-equiv=”X-FRAME-OPTIONS” content=”SAMEORIGIN”> 这种形式在document 的 header 里面设置,只能通过 http header 设置。

Browsers ignore the header if speicified in the META tag. So the following META will be ignored:

<meta http-equiv="X-Frame-Options" content="deny">

防止被IFRAME :把这些代码放到你的 header 里

<style id="antiClickjack">body{display:none !important;}</style>
<script>
if (self === top) {
var antiClickjack = document.getElementById("antiClickjack");
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
}
</script>
参考这个帖子
https://www.codemagi.com/blog/post/194

关于点击劫持 和 被iframe 的其他参考:

http://javascript.info/tutorial/clickjacking

http://blogs.msdn.com/b/ieinternals/archive/2010/03/30/combating-clickjacking-with-x-frame-options.aspx

https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options

带中文请求的URL 可能会返回400 需要 encodeURIComponent 处理.尤其是使用IE 的时候。

使用 X-Frame-Options 防止被iframe 造成跨域iframe 提交挂掉的更多相关文章

  1. 跨域iframe的高度自适应

    If you cannot hear the sound of the genuine in you, you will all of your life spend your days on the ...

  2. 使用postMesssage()实现跨域iframe页面间的信息传递----转载

    由于web同源策略的限制,当页面使用跨域iframe链接时,主页面与子页面是无法交互的,这对页面间的信息传递造成了不小的麻烦,经过一系列的尝试,最后我发现有以下方法可以实现: 1. 子页面url传参 ...

  3. 完美实现跨域Iframe高度自适应【Iframe跨域高度自适应解决方案】

    Iframe的强大功能偶就不多说了,它不但被开发人员经常运用,而且黑客们也常常使用它,总之用过的人知道它的强大之处,但是Iframe有个致命的“BUG”就是iframe的高度无法自动适应,这一点让很多 ...

  4. javascript跨域通信(一):利用location.hash实现跨域iframe自适应

    页面域关系: a.html所属域A:www.A.comb.html所属域B:www.B.com 问题本质: js对跨域iframe访问问题,因为要控制a.html中iframe的高度和宽度就必须首先读 ...

  5. 谷歌、火狐浏览器下实现JS跨域iframe高度自适应的完美解决方法,跨域调用JS不再是难题!

    谷歌.火狐浏览器下实现JS跨域iframe高度自适应的解决方法 导读:今天开发的时候遇到个iframe自适应高度的问题,相信大家对这个不陌生,但是一般我们都是在同一个项目使用iframe嵌套页面,这个 ...

  6. 跨域iframe高度计算

    一.同域获取iframe内容 这里有两个细节: 1. 取iframe内的文档对象,标准浏览器使用contentDocument属性,IE低版本(IE6,7,8)使用document属性. 2. cal ...

  7. 关于父窗口获取跨域iframe子窗口中的元素

    这几天在项目中遇到,一个难点, 就是需要异步加载一个pdf插件, 同时又需要获取这个插件中的点击事件来生成用户的下载记录. 刚开始也是想了很多方法,网上搜的 格式1:$("#iframe的I ...

  8. iframe操作(跨域解决等)

    note:当页面内嵌入一个iframe实际上是在dom上新建了一个新的完整的window对象 iframe中取得主窗体 window.top (顶级窗口的window对象) window.parent ...

  9. IE下IFrame引用跨域站点页面时,Session失效问题解决

    问题场景:在一个应用(集团门户)的某个page中, 通过IFrame的方式嵌入另一个应用(集团实时监管系统)的某个页面. 当两个应用的domain 不一样时, 在被嵌入的页面中Session失效.(s ...

随机推荐

  1. azkaban编译安装配置文档

    azkaban编译安装配置文档 参考官方文档: http://azkaban.github.io/azkaban/docs/latest/ azkaban的配置文件说明:http://azkaban. ...

  2. golang interface接口

    package main import "fmt" type Shaper interface { Area() float32 } type Square struct { si ...

  3. 42. Trapping Rain Water (Array,stack; DP)

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  4. MyBatis核心配置文件详解

    ------------------------siwuxie095                                     MyBatis 核心配置文件详解         1.核心 ...

  5. access数据库收缩(压缩)

    一般是因为表中有大量没用的数据,把没用的数据全部删除 菜单栏的“工具”——“数据库实用工具”——“压缩和修复数据库” OK啦

  6. git 常用命令笔记

    #提交代码会加上用户名和邮箱 git config --global user.name 名字 git config --global user.email 邮箱 git config --globa ...

  7. win下php5.4安装ffmpeg-php扩展

    1.ffmpeg的官网没有提供ffmpeg-php dll的扩展下载. http://ffmpeg-php.sourceforge.net/ 虽然在http://sourceforge.net/上提供 ...

  8. struts2框架之OGNL表达式概述(在代码中使用OGNL表达式)

    1. OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写 * 所谓对象图,即以任意一个对象为根,通过OGNL可以访问与这个对象关联的其它对象 * 通 ...

  9. 【原创】Silverlight的ComboBox.SelectValue无法赋值

      前几天开发中 给ComboBox的SelectValue属性赋值是,老是赋不上去.之前SelectValue为Null,执行完调试看下,还是Null.很诡异   ComboBox的SelectVa ...

  10. DB2与oracle类型对比

    本文摘自http://www.cnblogs.com/cy163/archive/2010/11/17/1880280.html 做过DB2数据库应用迁移的工程师,了解IBM MTK工具在迁移过程中所 ...