Posted By

pmw57 on 09/19/12


Tagged

url javascript js querystring parameters params


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

thescorpion
aaearhart
swapnilgg


Get URL Parameter


 / Published in: JavaScript
 

Code from https://snipt.net/geekyjohn/get-url-param/ updated so that most jslint issues are resolved, and updated the return to use a guard condition instead of a separate if statement.

  1. function getUrlParam(name) {
  2. var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
  3. return (results && results[1]) || undefined;
  4. }

Report this snippet  

You need to login to post a comment.