`
wenrunchang123
  • 浏览: 249233 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

iframe的document.domain问题

 
阅读更多

    使用iframe引用外部资源是相当便捷的手段,不过仅限于父页面不对iframe进行访问。当我们访问iframe文档中内容,时常会遇到跨域问题,导致对iframe里面的内容不可控,并且使用iframe对页面的性能有很大的影响。今天笔者遇到一个相当郁闷的问题,关于iframe的document.domain的设置。

 

有两个页面,一个是a.html为父页面,一个是b.html为iframe页面,域名都是domain.xx.com。

一般情况下,这种设置在各大浏览器都成功。

document.domain = "domain.xx.com";

document.domain = "xx.com";

 

但问题就来料,如果你把上面的两个语句顺序倒一下:

document.domain = "xx.com";

document.domain = "domain.xx.com";

以上两句代码,在浏览器中会报错。

 

由此看出,域可以由domain.xx.com修改为xx.com,所有浏览器都支持,而不能

从xx.com修改为domain.xx.com

分享到:
评论

相关推荐

    PHP ajax跨子域的解决方案之document.domain+iframe实例分析

    本文实例讲述了PHP ajax跨子域的解决方案之document.domain+iframe。分享给大家供大家参考,具体如下: 对于主域相同,子域不同,我们可以设置相同的document.domain来欺骗浏览器,达到跨子域的效果。 例如:我们有...

    Ajax跨域传输参数

    可以将book.aa.com用iframe添加到 www.aa.com的某个页面下,在www.aa.com和iframe里面都加上document.domain = "aa.com",这样就可以统一域了,可以实现跨域访问。就和平时同一个域中镶嵌iframe一样,直接调用里面的...

    通过伪协议解决父页面与iframe页面通信的问题

    我们经常会有父页面与iframe页面的操作,比如 <iframe id = “iframe”></iframe> 这个iframe里面的内容是js写的。...但有种情况,即父页面显式的写了document.domain = “xxx”; 在ie系列(IE10没

    cross-origin::cyclone: 跨域demo。CORS、JSONP、postMessage、websocket、document.domain、window.name、iframe等示例

    3000端口: 为前端界面,前端静态资源放在3000端口的服务器上3001端口: 为后端接口服务器目录Set Up运行环境node.js 全局安装npm 全局安装运行步骤git clone git@github.com:FatDong1/cross-domaincross-domain目录下...

    图库新版jQuery焦点图 JS代码

    // ad function dy(code) ...document.writeln ('<iframe width="120" height="24" frameborder="0" allowtransparency="true" marginwidth="0" marginheight="0" scrolling="no" border="0" src=...

    js操作iframe的一些方法介绍

    1. 获得iframe的window对象...文章Iframes, onload, and document.domain中说“he iframe element object has a property called contentDocument that contains the iframe’s document object, so you can use the

    前端常见跨域解决方案(全).mht

    2、 document.domain + iframe跨域 3、 location.hash + iframe 4、 window.name + iframe跨域 5、 postMessage跨域 6、 跨域资源共享(CORS) 7、 nginx代理跨域 8、 nodejs中间件代理跨域 9、 WebSocket...

    JavaScript使用HTML5的window.postMessage实现跨域通信例子

    当然解决方案也有很多: 1.document.domain+iframe的设置,应用于主域相同而子域不同; 2.利用iframe和location.hash,数据直接暴露在了url中,数据容量和类型都有限 3.Flash LocalConnection, 对象可在一个 SWF ...

    使用HTML5中postMessage知识点解决Ajax中POST跨域问题

    (1) document.domain+iframe; (2) 动态创建script; (3) iframe+location.hash; (4) flash。 postMessage是HTML5为解决js跨域问题而引入的新的API,允许多个iframe/window跨域通信。 HTML5中提供了在网页文档...

    cross-domain-events:类似事件的 api,用于 postMessage 在跨域框架之间发送对象

    跨域事件用于跨域通信的 postMessage 类事件接口。...// parent pagexde.on("resize", function (evt) {var iframe = document.getElementById("theiframe");iframe.style.width = evt.data.width;ifra

    Webkit的跨域安全问题说明

    父页面代码: 代码如下: [removed] document.domain = “nunumick.me”; function doTest(){ alert(‘hello world’); } [removed] <iframe src=”http://www.nunumick.me/lab/x-domain/webkit-test.html...

    HTML5中使用postMessage实现Ajax跨域请求的方法

    (1) document.domain+iframe;(2) 动态创建script; (3) iframe+location.hash; (4) flash。 这里不细说这几种方法,记录的是HTML5的window.postMessage。postMessage兼容IE8+、Firefox、Opera、Safari、Chrome。...

    AJAXCDR:利用 Flash 完美解决 JavaScript 和 AJAX 跨域 HTTP POST/GET 表单请求

     本域和子域的交互,可以通过iframe设置两个域名document.domain = "s135.com",实现统一s135.com域下的跨域访问。  本域和其他域的交互,可以通过iframe、代理、JS创建动态脚本等几种方法来实现,这里有篇文章对...

    cross-demos:多种跨域通信示例

    document.domain URL.hash Cross-fragment Window.name postMessage ##注意: 1-5请求都是发送到localhost:3000,为了实现跨域,打开页面时地址请使用127.0.0.1:3000 iframe需要配置hosts 127.0.0.1 www.myapp.com ...

    javascript跨域方法、原理以及出现问题解决方法(详解)

    基于iframe实现的跨域要求两个域具有aa.xx.com,bb.xx.com这种特点,也就是两个页面必须属于一个基础域(例如都是xxx.com,或是xxx.com.cn),使用同一协议(例如都是 http)和同一端口(例如都是80),这样在两个...

    js实现跨域访问的三种方法

    基于iframe实现的跨域要求两个域具有aa.xx.com,bb.xx.com这种特点,也就是两个页面必须属于一个基础域(例如都是xxx.com,或是xxx.com.cn),使用同一协议(例如都是 http)和同一端口(例如都是80),这样在两个...

    my97日历控件

    =V){var D=$.parent[N][C]("iframe");for(var F=0;F<D.length;F++){try{if(D[F].contentWindow==$){var E=W(D[F]);A+=E.left;_+=E.top;break}}catch(B){}}$=$.parent}return{"leftM":A,"topM":_}}function W(G,F){if...

    JavaScript同源策略和跨域访问实例详解

    浏览器的同源策略,限制了来自不同源的”document”或脚本,对当前”document”读取或设置某些属性。 (白帽子讲web安全[1]) 从一个域上加载的脚本不允许访问另外一个域的文档属性。 举个例子: 比如一个恶意网站的...

Global site tag (gtag.js) - Google Analytics