Skip to content

Instantly share code, notes, and snippets.

@ano
Created December 19, 2020 22:34
Show Gist options
  • Save ano/486736959a3950a25e3f99d8ecc216af to your computer and use it in GitHub Desktop.
Save ano/486736959a3950a25e3f99d8ecc216af to your computer and use it in GitHub Desktop.
JavaScript function to get URL parameters, similar to the PHP does it
/*
* Description: Get a URL parameter
* Usage:
* To get the value of the URL paramater search_term e.g. index.php?search_term=volvo
* var search = $_GET("search_term");
* console.log(search); //console output = "volvo"
*/
function $_GET(param){
const queryString = window.location.search; //console.log(queryString);
const urlParams = new URLSearchParams(queryString);
return urlParams.get(param);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment