Replace image.src with background.image.url
|
|
I am trying to replace a image.src with the url from it's background image.
var img = document.evaluate("//img[contains(@src, 'clear.cache.gif')]",document,null,9,null).singleNodeValue;
var imgbackground = img.style.background;
img.src = imgbackground;
imgbackground returns "transparent url(show.image.jpg) no-repeat scroll center center"; how do I just get "show.image.jpg" from transparent url instead? The Html example I am trying to modify is: <img class="imageViewMainImage" src="clear.cache.gif" style="background: transparent url(show.image.jpg) no-repeat scroll center center; height: 500px; width: 500px; visibility: visible; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" title="Use your mousewheel to navigate the image gallery."/> Thanks!!! (sorry for my poor newbie code) |
|
|
nm. Didn't read the question properly. |
|
|
this should do the trick: var img = document.evaluate("//img[contains(@src, 'clear.cache.gif')]",document,null,9,null).singleNodeValue;
var imgbackground = img.style.background.match(/url\(([^\)]+)/)[1];
img.src = imgbackground;
cheers. |
|
|
@avg, you rock!!! |
|
|
|
