How to get URL parameters with Javascript?


Javascript Problem Overview

> Possible Duplicate:
> How to get “GET” request parameters in JavaScript?
> jQuery querystring
> How can I get query string values in JavaScript?

Javascript does not provide a core method to do that, so how to do it?

Javascript Solutions

Solution 1 - Javascript

function getURLParameter(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec( || [null, ''])[1].replace(/\+/g, '%20')) || null;

So you can use:

myvar = getURLParameter('myvar');


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid MoralesView Question on Stackoverflow
Solution 1 - JavascriptDavid MoralesView Answer on Stackoverflow