var str = 'http://link1/link2/link3', newStr = str.substr(0, str.lastIndexOf('/')); alert(newStr);
var val='htpp://link1/link2/link3'; alert(val.replace(/\/[^\/]+$/,''));