Get URL Parameter


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. function getUrlParam(name) {
  2. var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
  3. return (results && results[1]) || undefined;
  4. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.