find substring from a URL | url substr
Iwouldrecommendusingaregexandasplit.HTML:
I would recommend using a regex and a split.
HTML:
<div id=url>http://www.xyz.com/#tabname-1-12</div>Javascript:
$(function() { // set this to the element containing the actual URL var url = $(#url).html(); // get tabname var tabname = url.match(/(#.+?)-/); tabname = tabname[1]; // you can now use the var tabname, which contains #tabname var ids = url.split(-); var idone = ids[1]; var idtwo = ids[2]; // idone contains 1, idtwo contains 12. });Use var tabname = url.match(/#(.+?)-/); if you dont want the # in front of tabname.
Working example: http://jsfiddle.net/QPxZX/[1]
References http://jsfiddle.net/QPxZX/ (jsfiddle.net)