Created
December 19, 2020 22:34
-
-
Save ano/486736959a3950a25e3f99d8ecc216af to your computer and use it in GitHub Desktop.
JavaScript function to get URL parameters, similar to the PHP does it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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