Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  185] [ 7]  / answers: 1 / hits: 66210  / 15 Years ago, sat, april 25, 2009, 12:00:00

Is it possible to get the actual URL (as opposed to the src attribute value) of an image within the current DOM using jQuery or JavaScript?



i.e. retrieve example.com/foo.jpg as opposed to foo.jpg (taking <base> elements into account)



What about any other interesting properties such as the mime type, file size or, best of all, the actual binary data?


More From » jquery

 Answers
0

I wonder if jQuery is using .getAttribute() - using .src always seems to give the absolute URL:



<img src=foo.jpg id=i>

<script>
var img = document.getElementById('i');

alert(img.getAttribute('src')); // foo.jpg
alert(img.src); // http://..../foo.jpg
</script>


To get the rest of the information, could you use an AJAX request and look at the header & data sent?


[#99650] Monday, April 20, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adriannemyiag

Total Points: 504
Total Questions: 105
Total Answers: 99

Location: Ecuador
Member since Thu, Apr 22, 2021
3 Years ago
;