最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - how to get "real" url from img src in javascript - Stack Overflow

programmeradmin0浏览0评论

I have piece of offline html like so:

<img src="../img/button.png"/>

and when I try to access the src attribute in JS, I get a different value than what's written in the html:

var s = myimg.src; // equals 'file:///V:/test/test1/img/button.png'

It's as if the value got resolved somewhere between the html and my call to 'src' attribute. How do I get the "original" value instead of the resolved one?

tnx

I have piece of offline html like so:

<img src="../img/button.png"/>

and when I try to access the src attribute in JS, I get a different value than what's written in the html:

var s = myimg.src; // equals 'file:///V:/test/test1/img/button.png'

It's as if the value got resolved somewhere between the html and my call to 'src' attribute. How do I get the "original" value instead of the resolved one?

tnx

Share Improve this question asked Aug 6, 2011 at 11:09 Sagi MannSagi Mann 3,6209 gold badges44 silver badges83 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

use getAttribute

var s = myimg.getAttribute('src')

If you read the attribute instead of the src property, you get the original value:

var s = myimg.getAttribute('src');
发布评论

评论列表(0)

  1. 暂无评论