JavaScript Function to get QueryString Parameters

Posted on 10/1/2014 @ 4:36 PM in #Vanilla .NET by | Feedback | 6192 views

Title descibes it all, here is your function, works with “#” URLs too like SharePoint MDS uses.

 

   1:  function getParameterByName(name) {
   2:      name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
   3:      var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
   4:          results = regex.exec(location.search);
   5:      return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
   6:  }
   7:   
   8:  var accountName = getParameterByName('AccountName');

Sound off but keep it civil:

Older comments..