Get the width and height of a dynamically loaded image - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Get the width and height of a dynamically loaded image

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/* w ww . j av  a2s . co m*/
var img = new Image();
img.onload = function(){
    console.log('Width: ' + img.width +', Height: ' + img.height);
}
img.src = 'http://www.google.com/images/logos/ps_logo2.png';
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials