Search code examples
javascriptstrip

Javascript function to strip user ID from URL


i need a javascript function to strip the user ID from a given URL. for example. i have this URL http://www.example.com/member.php?id=100001877097904 how can i retrieve the ID of the user from that URL? Thanks in advance.


Solution

  • function getParameterByName(url, name)
    {
      name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
      var regexS = "[\\?&]" + name + "=([^&#]*)";
      var regex = new RegExp(regexS);
      var results = regex.exec(url);
      if(results == null)
        return "";
      else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
    }