0

I'm successfully displaying a photo in Firefox version 22 -- in two different img tags -- one of the img tags has no CSS width or height set, and so the image appears in its original size.

The second img tag is set by a CSS style to be 60px by 60px.

When I set the 'innerHTML' of these two img tags, in Firefox I see the original-size image and the same image shrunk down to fit in the 60px by 60px img tag.

In IE version 10.0.9, I simply do not see anything in the second img tax that is set to be 60px by 60px via CSS.

It's the exact same code that's executing. Is there something I need to do for IE to show the image in the 60px by 60px img tag that is not present in my code here?

By the way, the code below is generated in a PHP file -- I use the 'hidden Iframe' approach to load then display the image on the web page -- the code below is generated in a PHP file then outputs what you see below to my hidden iframe on my html page, which is why you see the code here getting the parent document of the iframe:

<script language="JavaScript" type="text/javascript">
var parDoc = parent.document;

parDoc.getElementById('justOpenedImage').innerHTML = 
   '<div><img src=\'http://localhost/thesite/aPhoto.jpg\' /></div>';

parDoc.getElementById('60by60').innerHTML = 
  '<div><img class="60by60Image" src=\'http://localhost/thesite/aPhoto.jpg\' /></div>';
</script>

Here is the CSS class 60by60Image:

 .60by60Image
 {
    border: 2px solid green;   
    width: 60px; 
    height: 60px;
    display: inline-block;
 }

Here is the html on the page:

     <!-- THE ORIGINAL-SIZED IMAGE APPEARS FINE HERE IN BOTH IE AND FF -->
     <div id="justOpenedImage"></div>


     <!-- THE SMALLER IMAGE APPEARS HERE IN FIREFOX BUT NOT IN IE -->
     <div>
         <img class="60by60Image"  id="60by60" src="" />
     </div>

This has been working fine in Firefox but in IE it fails to show the smaller 60 by 60 version of the image -- not sure why.

CFHcoder
  • 429
  • 2
  • 8
  • 25

1 Answers1

4

You set the innerHTML of the image. After execution of your script, the document tree looks something like this:

 <div>
     <img class="60by60Image"  id="60by60" src="">
         <div><img class="60by60Image" src='http://localhost/thesite/aPhoto.jpg' /></div>
     </img>
 </div>

I think IE just does not 'handle' this. At least, it is not valid HTML.

You can fix this by adding the id="60by60" attribute to the parent div, and remove it from the img. Letting javascript change the innerHTML of the div instead of the image.

<div id="60by60">
     <img class="60by60Image" src="">
</div>

Or change the src attribute of the image.

parDoc.getElementById('60by60').src = 'http://localhost/thesite/aPhoto.jpg';
AmazingDreams
  • 3,136
  • 2
  • 22
  • 32
  • I changed my code for the 60px by 60px image to use your 2nd suggestion -- parDoc.getElementById('60by60').src = 'http//localhost/thesite/aPhoto.jpg\'; and that works in both Firefox and in IE -- thanks. – CFHcoder Aug 03 '13 at 16:46