最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - document.domain "permission denied" issues with IE8 - Stack Overflow

programmeradmin1浏览0评论

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 (code within page):

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

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

<script>
document.domain = "mysite";

$(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.

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. (code within page):

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

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

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

$(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.

Share Improve this question asked Dec 12, 2010 at 23:57 GabGab 511 gold badge1 silver badge2 bronze badges 1
  • possible duplicate of Permission Denied IE iFrame – alex Commented Dec 13, 2010 at 0:10
Add a ment  | 

3 Answers 3

Reset to default 2

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..

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

  • http://waelchatila./2007/10/31/1193851500000.html

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 ment 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

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.

发布评论

评论列表(0)

  1. 暂无评论