开发者

how to get "real" url from img src in javascript

开发者 https://www.devze.com 2023-03-26 03:25 出处:网络
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 开发者_StackOverflowvalue than what\'s written in th

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 开发者_StackOverflowvalue 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


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

精彩评论

暂无评论...
验证码 换一张
取 消