Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.domain "permission denied" issues with IE8

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.

like image 774
Gab Avatar asked Oct 13 '22 19:10

Gab


2 Answers

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

like image 183
damian Avatar answered Oct 18 '22 03:10

damian


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
like image 28
icyrock.com Avatar answered Oct 18 '22 02:10

icyrock.com