Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>if the document.domain property is set in the parent page, Internet Explorer gives me an "Access is denied"</p> </blockquote> <p>Sigh. Yeah, it's an IE issue (bug? difficult to say as there is no documented standard for this kind of unpleasantness). When you create a srcless iframe it receives a <code>document.domain</code> from the parent document's <code>location.host</code> instead of its <code>document.domain</code>. At that point you've pretty much lost as you can't change it.</p> <p>A horrendous workaround is to set <code>src</code> to a javascript: URL (urgh!):</p> <pre><code> iframe.src= "javascript:'&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello&lt;\/p&gt;&lt;script&gt;do things;&lt;\/script&gt;'"; </code></pre> <p>But for some reason, such a document is unable to set its own <code>document.domain</code> from script in IE (good old “unspecified error”), so you can't use that to regain a bridge between the parent(*). You <em>could</em> use it to write the whole document HTML, assuming the widget doesn't need to talk to its parent document once it's instantiated.</p> <p>However iframe JavaScript URLs don't work in Safari, so you'd still need some kind of browser-sniffing to choose which method to use.</p> <p>*: For some other reason, you <em>can</em>, in IE, set <code>document.domain</code> from a second document, document.written by the first document. So this works:</p> <pre><code>if (isIE) iframe.src= "javascript:'&lt;script&gt;window.onload=function(){document.write(\\'&lt;script&gt;document.domain=\\\""+document.domain+"\\\";&lt;\\\\/script&gt;\\');document.close();};&lt;\/script&gt;'"; </code></pre> <p>At this point the hideousness level is too high for me, I'm out. I'd do the external HTML like David said.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload