I've got a url like this:
http://www.site.com/234234234
I need to grab the Id after /, so in this case 234234234
How can i do this easily?
I've got a url like this:
http://www.site.com/234234234
I need to grab the Id after /, so in this case 234234234
How can i do this easily?
var url = "http://www.site.com/234234234"
var stuff = url.split('/');
var id = stuff[stuff.length-1];
//id = 234234234
Get a substring after the last index of /.
var url = 'http://www.site.com/234234234';
var id = url.substring(url.lastIndexOf('/') + 1);
alert(id); // 234234234
It's just basic JavaScript, no jQuery involved.
Using the jQuery URL Parser plugin, you should be able to do this:
jQuery.url.segment(1)
var url = window.location.pathname;
var id = url.substring(url.lastIndexOf('/') + 1);
var full_url = document.URL; // Get current url
var url_array = full_url.split('/') // Split the string into an array with / as separator
var last_segment = url_array[url_array.length-1]; // Get the last part of the array (-1)
alert( last_segment ); // Alert last segment
Just because I can:
function pathName(url, a) {
return (a = document.createElement('a'), a.href = url, a.pathname); //optionally, remove leading '/'
}
pathName("http://www.site.com/234234234") -> "/234234234"