getparameterbyname

Get query string values without jQuery.


Keywords
nodejs
License
CC-BY-SA-3.0
Install
npm install getparameterbyname@1.0.3

Documentation

getParameterByName

Build Status

Stackoverflow answer packaged as NPM package.

Usage

Use in browser

<script src="https://unpkg.com/getparameterbyname/dist/bundle.min.js"></script>

<script>
  const url = 'https://www.example.com/search?q=nodejs';

  const queryParameterValue = getQueryParameterByName('q', url);

  // Print queryParameterValue to console
  console.log(queryParameterValue);
</script>

Get query parameter from url

import getQueryParameterByName from 'getqueryparameterbyname';

const url = 'https://www.example.com/search?q=nodejs';

const queryParameterValue = getQueryParameterByName('q', url);

If no second parameter is set, window.location.href is used.