Last active
February 27, 2022 15:29
-
-
Save themegabyte/fc87ad5494ca6ea6254aa79e24646c62 to your computer and use it in GitHub Desktop.
Get a variable from the URL parameters, similar to PHP $_GET
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
function getQueryVariable(variable) { | |
var svalue = location.search.match( | |
new RegExp("[?&]" + variable + "=([^&]*)(&?)", "i") | |
); | |
return svalue ? svalue[1] : svalue; | |
} | |
// ?page=1 | |
getQueryVariable("page"); // 1 | |
// courtesy: https://css-tricks.com/snippets/javascript/get-url-variables/#comment-63646 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment