小编smi*_*lay的帖子

在document.domain更改后,无法在IE中访问about:blank iframe

有没有人知道about:blank在IE document.domain更改时在IE页面上创建iframe 的任何变通方法?

document.domain在更改属性后,IE似乎不允许访问空/动态iframe .

例如,假设您正在动态创建iframe,然后将一些html注入其中:

// Somewhere else, some 3rd party code changes the domain 
// from something.foo.com to foo.com 
document.domain = 'jshell.net';

var iframe = document.createElement('iframe');
document.body.appendChild(iframe);

// In IE, we can't access the iframe's contentWindow! Access is denied.
iframe.contentWindow.document.body.style.backgroundColor = 'red';
Run Code Online (Sandbox Code Playgroud)

这是jsfiddle的实例:http://jsfiddle.net/XHkUT/

您会注意到它在FF/Webkit中运行良好,但不适用于IE.这特别令人沮丧,因为这会影响属性更改创建的iframe document.domain(如上例所示).

IE规则似乎是"如果您在更改后创建动态/空iframe document.domain,则无法访问其DOM."

将iframe设置srcabout:blank javascript:void(0)或未javascript:""成功.

javascript iframe internet-explorer dom cross-domain-policy

10
推荐指数
1
解决办法
6248
查看次数

IE10是否更改了window.location.port的定义?

我注意到window.location.port今天在IE10平台预览10.0.1008.16421 中检查了一些JavaScript代码.

例如,在IE10中,请访问http://www.microsoft.com.打开开发人员工具并输入window.location.port并返回80.发生了什么?80当所有其他IE浏览器""在同一站点上返回(空字符串)时,为什么IE10会突然返回整数?IE10也会80以所有下层模式返回.

http://www.microsoft.com上比较IE8/9的结果:window.location.port""!

不知道这是IE10的新行为,平台版本中记录的错误,还是尚未报告的错误?

javascript dom internet-explorer-10

8
推荐指数
1
解决办法
1449
查看次数