2 Replies Latest reply on Aug 29, 2013 2:51 PM by GregT42

    Problem with Images only in Chrome

    GregT42

      At the bottom of each HTM file I have a small script that runs. Works fine on IE/FF, not so well on Chrome.

      ...

      <script type="text/javascript">//<![CDATA[

      InitImages();

      //]]></script>

      </body>

      </html>

       

      The code is designed to access the attribute width of the image and the native width.

      function InitImages() {

          var imgs = document.getElementsByTagName('img');

          for (var i = 0; i < imgs.length; i++) {

              var thisimg = imgs[i];

              var thisimgwidth = thisimg.getAttribute('width');

              var thisimgheight = thisimg.getAttribute('height');

              var theImage = new Image();

              theImage.src = thisimg.getAttribute('src');

              var imageWidth = theImage.width;

              var imageHeight = theImage.height;

      ...

       

      In Chrome, imageWidth (actual width of the image) is always 0 the first time you load the page. On reload the correct width is detected. If you close the browser or open the page in a new tab then you have to load the page twice again.

       

      Any ideas on how to get this working in Chrome?

       

      Thank you