If I have a url https://stackoverflow.com/?variable=12345 how can I check if there is a GET parameter in the URL and what it is equals to in JS or jQuery?
For example in PHP:
if(isset($_GET['variable']))
$variable = $_GET['variable'];
Thanks.
If I have a url https://stackoverflow.com/?variable=12345 how can I check if there is a GET parameter in the URL and what it is equals to in JS or jQuery?
For example in PHP:
if(isset($_GET['variable']))
$variable = $_GET['variable'];
Thanks.
function get_var(var_name){
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == var_name){return pair[1];}
}
return(false);
}
And to use:
var get_variable = get_var("variable");
if (get_variable !== '') {
// Variable exists
}