Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting the absolute path of a <img/>

Using Javascript, is there a standard way to get the absolute path of an image? img.getAttribute("src") only returns the src attribute as it was declared in the HTML.

like image 371
Pierre Avatar asked Aug 16 '10 19:08

Pierre


People also ask

How do I find the absolute path of a path?

The function getAbsolutePath() will return the absolute (complete) path from the root directories. If the file object is created with an absolute path then getPath() and getAbsolutePath() will give the same results.


1 Answers

Just do .src.

$('img')[0].src = '/images/foo.gif'
"/images/foo.gif"
$('img')[0].src
"http://stackoverflow.com/images/foo.gif"
$('img')[0].getAttribute('src')
"/images/foo.gif"
like image 90
meder omuraliev Avatar answered Oct 04 '22 20:10

meder omuraliev