Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining Image Properties with JavaScript 3

Status
Not open for further replies.

Cannibal100

Technical User
Joined
Jan 13, 2004
Messages
2
Location
GB
Hi, how can you get the properties of an image with JavaScript? Thanks.
 
This should get you started:
Code:
   ...
   <script type=&quot;text/javascript&quot; language=&quot;JavaScript&quot;>
      function showSomeImageProperties(aImage) {
         window.alert(&quot;Image: &quot; + aImage.src + &quot;\nWidth: &quot; + aImage.width + &quot;\nHeight: &quot; + aImage.height&quot;);
         return;
      }
   </script>
   ...
   <body>
      ...
      <img src=&quot;someimg.gif&quot; onclick=&quot;showSomeImageProperties(this);&quot;/>
      ...
   </body>

The see
for more information on the exposed properties of the [tt]img[/tt] object.

________________________________________
[hippy]Roger J Coult; Grimsby, UK
In the game of life the dice have an odd number of sides.
 

You can access loads of properties in any object is you pass it to a function like this:
Code:
function showProps( obj ) {

	for( var prop in obj ) {

		document.body.innerHTML +=
			&quot;<p>Property: &quot; + prop + &quot;; Value: &quot; + obj[ prop ] + &quot;</p>&quot;;
	}
}

HTH.
 
cool trick theboyhope

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top