Jump to content

Getting Image Source


adam291086

Recommended Posts

Correct me if i am wrong but you want the actual size of the image am i right?

 

There is 2 ways to solve that problem.

 

1. get the image width server side.

 

2. Get the image width when the page has fully loaded. I found a quick way to solve that using mootools

 

/* Load Event fires when the whole page is loaded, included all images */
window.addEvent('load', function() {
  //in here you can execute your function to get your image width since the page has fully loaded
});

 

 

 

 

Link to comment
Share on other sites

@ DJ Kat

 

I am new to javascript. That function will load when the window loads. How can i call on a varable out of that function.

 

/* Load Event fires when the whole page is loaded, included all images */
window.addEvent('load', function() {
var adam = document.getElementById("myimage").height
});

 

 

how can i call upon adam later on

Link to comment
Share on other sites

I'm sure this will help you out this is a fully working example

 

<script src="mootools-release-1.11.js"></script>
<script>

window.addEvent('load', function() {
  
  //the $("myimage") equals the document.getElementById("myimage") method mootools style
  var imageElement=$("myimage");
  
  //create an image object
  var image= new Image();
  
  //set the source of the image object
  image.src = $("myimage").src ;
  
  //alert the image height
  alert(image.height);

});
</script>
<img id="myimage" src="2426402588_f7486e0eb2.jpg" />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.