开发者

document.domain "permission denied" issues with IE8

开发者 https://www.devze.com 2023-01-30 00:32 出处:网络
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 m

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.


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 comments about a few possible problems:

  • http://waelchatila.com/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 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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号