开发者

Strip out portion of a url using jquery

Google produces image thumbs like so http://images.google.com/images?q=tbn:9vPPg9Y5ojFMeM::www.maniacworld.com/amazing-cars.jpg

I only need the main image url which in this case is www.maniacworl开发者_开发技巧d.com/amazing-cars.jpg I noticed we have :: before the main image url

What is the easiest way to do this via jquery.


You don't need jquery, you can probably just use a regular expression.

var re= /.+::/
var newurl = googleurl.replace(re,'');

Here's a working demo: http://jsfiddle.net/Rsefq/


If you want to use jQuery something like this should work:

  var result = [yourstring].split("::")[1];

Working Demo


var str = 'http://images.google.com/images?q=tbn:9vPPg9Y5ojFMeM::www.maniacworld.com/amazing-cars.jpg';
alert(str.split('::')[1]);


I'd do it with JavaScript's split() method if you're sure "::" will always proceed what you're after.

var parts = url.split("::");
var image_url = parts[1];


you dont need jquery you can simply use string split with javascript, but if you want jquery here you go:

$('urlSelector').attr('href').split('::')[1]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜