Wednesday, 20 September 2017

how to get GET variable's value in javascript?











how can i get the get variable in javascript?



i want to pass it in jquery function.



function updateTabs(){

//var number=$_GET['number']; how can i do this?
alert(number);
$( "#tabs" ).tabs({ selected: number });


}

Answer



var $_GET = {};
if(document.location.toString().indexOf('?') !== -1) {
var query = document.location
.toString()
// get the query string
.replace(/^.*?\?/, '')

// and remove any existing hash string (thanks, @vrijdenker)
.replace(/#.*$/, '')
.split('&');

for(var i=0, l=query.length; i var aux = decodeURIComponent(query[i]).split('=');
$_GET[aux[0]] = aux[1];
}
}
//get the 'index' query parameter

alert($_GET['index']);

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...