Pronunciation / adjective
Bringing something good and unforseen.
    Skip Navigation Links > Code Repository
   

Get QueryString Value by Name with Javascript



 
Return

Get QueryString Value by Name with Javascript

The following javascript function returns the value found for any querystring parameter name passed to it.

  1. <script type="text/javascript">
  2. function getParameterByName(name)
  3. {
  4. name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  5. var regexS = "[\\?&]" + name + "=([^&#]*)";
  6. var regex = new RegExp(regexS);
  7. var results = regex.exec(window.location.href);
  8. if (results == null)
  9. {
  10. return "";
  11. }
  12. else
  13. {
  14. return decodeURIComponent(results[1].replace(/\+/g, " "));
  15. }
  16. }
  17. </script>


Return
Microsoft Certified Professional   © 2017 Fortunate.  All rights reserved.
contact: justin@aboutfortunate.com