0

I am "lazy loading" a 3rd party ad script on my website by overwriting the document.write function and restoring it at a later time. This ad script creates an iframe, and tries to write to it.

I am seeing an "Access is denied" error in Internet Explorer 8 (but not in FF, Safari, or Chrome) when the script tries to access frame.document. The frame exists (I can see it in IE8 Developer Tools)

Any idea why this is happening? Could it be because the iframe is not ready or because of cross-site security restrictions (which I don't fully understand)?

Bilal and Olga
  • 3,101
  • 5
  • 27
  • 30
  • 1
    IE is a pain with cross domain security. I'm guessing the iframe is not in you domain? – aepheus Feb 16 '10 at 21:14
  • I do not have a domain set explicitly on my page (it's a simple ... kind of deal). The 3rd party script creates the iframe, and I don't believe it's setting the domain explicitly either, but I'm guessing the domain gets set to the remote server's URI. – Bilal and Olga Feb 16 '10 at 23:39
  • @BilalAslam, I've been looking at the great answers below and was wondering if this turned out to be a domain issue after all? – WynandB Jan 11 '13 at 01:41

2 Answers2

1

Just a shot in the dark here without seeing your code, but check to see if you have document.domain explicitly set on your page. If you are setting the domain of the document, trying to access a dynamically injected iFrame can throw access errors in IE. For example, if the following is set try commenting it out just to test:

//document.domain = "mydomain.com";
johnmdonahue
  • 653
  • 7
  • 16
0

It depends on the context from which you're trying to access frame.document.

For example, say you load up your page on foo.com. It in turn loads up an ad running on ad.com in a frame called "myFrame".

If, in a script block on foo.com, you try to access myFrame.document, you're going to get a complaint, since the pages don't live on the same domain. You can reference the document from inside the iframe, but not outside.

That's the basics of cross-site security. If you can give us more info on the snippet that's actually causing the problem, and on which domain the various pieces are running, we might be able to help more.

jvenema
  • 42,243
  • 5
  • 64
  • 107