document.domain“权限被拒绝” IE8 的问题

发布于 2024-10-07 22:35:15 字数 796 浏览 0 评论 0原文

我目前正在尝试使用 iframe 将子域中的页面加载到我的主域上,并让子域在我的主域中调用 javascript 函数(当 dom 就绪时),以便主域可以根据内容的高度调整iframe的大小。 这是一个示例

www.mysite.com (页面内的代码):

<script type="text/javascript">
document.domain = "mysite.com";
function doSomething() {
    //do something
}
</script>
<iframe id="mytestid" src="test.mysite.com" height="0" width="900"></iframe>

对于我的另一个网站 test.mysite.com,这是页面内的代码:

<script>
document.domain = "mysite.com";

$(document).ready(function () {
    window.parent.doSomething();
});
</script>

这似乎适用于 firefox、safari 和 chrome,但不适用于IE8。 IE8 在调用 window.parent.doSomething() 时总是给出“权限被拒绝”错误

我无法在 IE7 或 IE6 上进行测试以查看问题是否仍然存在,但有人知道吗遇到这个问题吗?我布置代码的方式是否遗漏了一些东西?

谢谢你们的帮助。

I'm currently trying to load a page within a sub-domain, onto my main domain, using an iframe, and have the sub-domain call a javascript function (when dom-ready) within my main domain, so that the main domain can resize the iframe according to the height of the content.
Here's an example

www.mysite.com (code within page):

<script type="text/javascript">
document.domain = "mysite.com";
function doSomething() {
    //do something
}
</script>
<iframe id="mytestid" src="test.mysite.com" height="0" width="900"></iframe>

And for my other site, test.mysite.com, here's the code within the page:

<script>
document.domain = "mysite.com";

$(document).ready(function () {
    window.parent.doSomething();
});
</script>

This seems to work just fine for firefox, safari, and chrome, but not for IE8.
IE8 always gives me a "permission denied" error when making the call window.parent.doSomething()

I haven't been able to test on IE7 or IE6 to see if the problem persists, but has anyone encountered this problem? Have I missed something with the way I'm laying out the code?

Thanks for the help guys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

舞袖。长 2024-10-14 22:35:15

IE8 的 document.domain“权限被拒绝”问题已解决!!

就像其他用户所说,只需在设置 iframe 所在页面的 document.domain 之后设置几秒的超时,然后在 iframe 中调用第二个页面。

你需要设置 iframe 的 SRC 值,在 IE8 上设置 document.domain 几秒钟后它就会起作用。

document.domain “permission denied” issues with IE8 SOLVED!!

just like other user said, just set a timeout of a couple o seconds after set document.domain where the iframe is on page, and then call your second page within the iframe.

you need to set the SRC value of your iframe, a couple of seconds after you set document.domain on IE8 and it will work..

年少掌心 2024-10-14 22:35:15

这是一个关于一些可能的问题的帖子,其中有很多评论:

注意我没有测试这个,因为我没有 IE。不幸的是,从我的角度来看,两者似乎都没有说服力 - 尝试一下,看看它是否适合您。

因此,从上面的帖子来看,似乎有两个可能的原因:

  • 该帖子声称 IE 要求所有文档具有相同的域。如果您有更多文档(iframes 等),请尝试删除它们并仅使用这两个文档(主文件和 iframe)进行测试。
  • 请参阅帖子中的最后一条评论 - 这可能只是一个竞争条件。尝试将其放入 setTimeout 中,在两个页面将 document.domain 设置为相同值后等待几秒钟

Here's a thread with a lot of comments about a few possible problems:

Note that I did not test this, as I don't have IE. Unfortunately, neither seem to convincing from my perspective - try it and see if it works for you.

So, from the above post, it seems there are two possible causes:

  • The post alleges IE requires all documents to have the same domain. If you have more documents (iframes and such), try removing them and testing with just these two (main and iframe)
  • See the last comment in the post - it might just be a race condition. Try putting it in a setTimeout with a few seconds of waiting after both pages have set document.domain to the same value
花开柳相依 2024-10-14 22:35:15

我遇到了同样的问题,并且使用超时并没有解决问题。

由于我有另一个具有类似设置且一切正常的站点,因此我并排打开了两个窗口,并注意到底部的状态栏中一个位于“本地 Intranet”下,另一个位于“受信任的站点”下。

这导致我要检查另一点:确保两个子域出现在 IE 的 Internet 安全属性中的同一安全区域中!如果他们不这样做,那么您将收到“权限被拒绝”错误。

I ran in the same issue and using a timeout didn't solve the issue.

As I had another site with similar settings where all was working fine, I opened both windows side by side and noticed in the status bar at the bottom that one was under "Local Intranet" while the other was under "Trusted Sites".

This led me to another point to check : make sure that both sub-domains appear in the same Security Zone in IE's Internet Security Properties ! If they don't, then you'll have a "Permission denied" error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文