7

I have an iframe:

<iframe src="http://externaldomain.com/something.html">

If something.html from externaldomain.com has the css:

html { position: relative; }

In IE, it will render the iframe as blank. All other browser are fine.

Anyone know of a solution? Remember the same origin policy. I cannot alter anything within the iframe with javascript or change the css as the iframe src is external.

Thanks.

Michael Haren
  • 105,752
  • 40
  • 168
  • 205
Josh R
  • 105
  • 1
  • 1
  • 3

4 Answers4

8

Use the following syntax it will work.

Give the style="position:relative;" to your iframe it will work in IE.

  • Sometimes, iframe contains page information but it get squeezed. In that case, iframe should have min-height, min-width value to encounter that problem – kidz Jul 08 '14 at 10:11
1

As a workaround, if all else fails, you can download the contents of something.html using server-side logic, like ASP.NET or PHP, and save it on your local web-server somewhere. Then you can avoid the same-origin policy, or you can even modify the HTML/CSS yourself on the server, for ex., remove the offending position:relative.

Mr. TA
  • 5,230
  • 1
  • 28
  • 35
  • This is a very bad solution! First of all, you could end up with copyrighted material on your own server. Then there's the matter of relative paths to images and such not working, and even if you change those to absolute paths you're going to end up with images not loading due to hotlink protection and such... – patrick Jul 10 '13 at 17:29
  • 1
    @patrick Agreed, but the question describes a very awkward situation to begin with. If copyright is a problem, one could just download it from the target site and pass it on each request (sub-optimal performance, of course). Hotlink protection is a possible issue, but I can't know for sure what the situation is with that. And regarding relative paths, you answered your own question. That is why I prefixed my answer with "As a workaround, if all else fails ..." – Mr. TA Jul 11 '13 at 18:15
1

I would start by reading this Another Cross Domain iFrame Communication Technique and then look at a more elegant AJAX solution. I have seen a lot of situations where cross-domain iframes just don't work (and for good reason).

IFrames are one step above IE in the Axis of Evil (IMO)

Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
PseudoNinja
  • 2,846
  • 1
  • 27
  • 37
0

iframe must have attribute ID

window.parent.document.getElementById('iframeid').contentWindow.document.execCommand('print', false, null);
Farhan C K
  • 1,159
  • 18
  • 35
Simer
  • 572
  • 1
  • 7
  • 15