Reputation: 3183
I'm using jquery to find and retrieve several img src's from the DOM, however the src's are in relative path format like this:
src="../../../../../dynamic/eshop/product_images/thumbnail_cache/366x366/042-1392_13760000.1.jpg"
I need to remove all the trailing slashes and append an absolute url. Is there anyway to achieve this without using regex in javascript or jquery?
Upvotes: 2
Views: 3849
Reputation: 10994
Given the URL
var url = '../../../../../dynamic/eshop/product_images/thumbnail_cache/366x366/042-1392_13760000.1.jpg';
Using regex
var fullurl = url.replace(/^.+\.\//,'');
Using index
var inx = url.lastIndexOf('./');
var fullurl2 = url.substring(inx+2, url.length)
Normal replace (if you're sure you only have ../
)
url.replace(/\.\.\//g, '');
Upvotes: 5