IE8 Javascript document.domain error

狂风中的少年 提交于 2019-12-24 17:15:37

问题


I need to change the domain of the document and then set it back again to the original value.

It looks something like this [the page is on domain 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 ())
}

The problem is that this works fine on IE6 (I did not test on 7). But it gives me an error [Invalid argument] when i execute the second document.domain.

Is there any way to "reset" the domain of the document in IE8?


回答1:


The problem is you cannot set document.domain to a more strict value once you set it to top-domain only.

From the MSDN blog:

Put simply, once you’ve loosened document.domain, you cannot tighten it.

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




回答2:


Use script tag with type text/cjs:

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


来源:https://stackoverflow.com/questions/3657710/ie8-javascript-document-domain-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!