Site icon Puneet Sharma – Freelance Web Developer

Get the get-values from URL – jQuery

Here is a function that you can use to get the get-values from URLs and can use it to manipulate web pages on document load.

get-values from URL – jQuery

var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = window.location.search.substring(1),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
        }
    }
};

$(document).ready(function(){
  var tab = getUrlParameter('tab'); // Assigning value to local variale
  if( tab == 'settings' ){
    $('#custom-tabs__settings').click();
  }
});
Exit mobile version