Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery - Get URL Parameters

0 votes
9 views
added Jul 4, 2018 in jQuery by birdygeek Sergeant (2,060 points)
//Example website URL
 "http://yoursite.com/?language=php&blog=techtalk". 

//Create function which returns value of any parameters variable
function GetURLParameter(sParam) {
    var sPageURL = window.location.search.substring(1),
        sURLVariables = sPageURL.split('&');

    for (var i = 0; i < sURLVariables.length; i++) {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam)   {
          return sParameterName[1];
        }
    }
}​

//variable
var lang = GetURLParameter('php');
var blog = GetURLParameter('techtalk');

//Above variable will output:
// --> 'lang' variable = 'php' value
// --> 'blog' variable =  'techtalk' value

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...