IE8 Javascript document.domain错误

时间:2010-09-07 10:16:01

标签: javascript internet-explorer-8 dns

我需要更改文档的域名,然后再将其重新设置为原始值。

它看起来像这样[页面在域base.site.com上]:

function execute ()
{
document.domain = "site.com";

// Access an object that is on another frame, but did the same set of the domain

document.domain = "base.site.com";

// Access an object that is on this page (window.createPopup ())
}

问题是这在IE6上工作正常(我没有在7上测试)。 但是当我执行第二个document.domain时,它给我一个错误[无效参数]。

有没有办法在IE8中“重置”文档的域名?

2 个答案:

答案 0 :(得分:1)

问题是,一旦将document.domain设置为top-domain,就无法将document.domain设置为更严格的值。

来自MSDN博客:

  

简单地说,一旦你放松了document.domain,你就无法收紧它。

http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx

答案 1 :(得分:0)

使用类型为text/cjs的脚本标记:

<script type="text/cjs">
document.domain = '<your domain host value>';
</script>