Нет необходимости разбирать строки URL.В браузере есть собственный анализатор URL, доступ к которому можно получить с помощью location
-подобных свойств HTMLAnchorElement
:
var a= document.createElement('a');
a.href= 'http://www.example.com/index.php?id=ss';
alert(a.protocol); // http
alert(a.hostname); // www.example.com
alert(a.pathname); // /index.php
alert(a.search); // ?id=ss
// also port, hash