var newsUrl = window.location.href, newsSplit = newsUrl.split('/'), newsId = newsSplit[newsSplit.length-2]; console.log(newsId); // e.g URL: // http://yoursite.com/content/1643743/defender-110-td5-2006-England // output newsId // 1643743
function currentID() { var current_path = window.location.pathname; var path_arr = current_path.split("/"); return path_arr[2]; }