Skip to main content
added 10 characters in body
Source Link
Ben Call
  • 976
  • 1
  • 10
  • 16
 var DeparamExample = function() {
            var params = $.deparam.querystring();

            //nameofparam is the name of a param from url
            //code below will get param if ajax refresh with hash
            if (typeof params.nameofparam == 'undefined') {
                params = jQuery.deparam.fragment(window.location.href);
            }
            
            if (typeof params.qnameofparam != 'undefined') {
                var paramValue = params.nameofparam.toString();
                  
            }
        };
 var DeparamExample = function() {
            var params = $.deparam.querystring();

            //nameofparam is the name of a param from url
            //code below will get param if ajax refresh with hash
            if (typeof params.nameofparam == 'undefined') {
                params = jQuery.deparam.fragment(window.location.href);
            }
            
            if (typeof params.q != 'undefined') {
                var paramValue = params.nameofparam.toString();
                  
            }
        };
 var DeparamExample = function() {
            var params = $.deparam.querystring();

            //nameofparam is the name of a param from url
            //code below will get param if ajax refresh with hash
            if (typeof params.nameofparam == 'undefined') {
                params = jQuery.deparam.fragment(window.location.href);
            }
            
            if (typeof params.nameofparam != 'undefined') {
                var paramValue = params.nameofparam.toString();
                  
            }
        };
added 37 characters in body
Source Link
Ben Call
  • 976
  • 1
  • 10
  • 16

Edit: Adding Deparam Example:

 var DeparamExample = function() {
            var params = $.deparam.querystring();

            //nameofparam is the name of a param from url
            //code below will get param if ajax refresh with hash
            if (typeof params.nameofparam == 'undefined') {
                params = jQuery.deparam.fragment(window.location.href);
            }
            
            if (typeof params.q != 'undefined') {
                var paramValue = params.nameofparam.toString();
                  
            }
        };

If you want to just use plain JavaScript, you could use...

If you want to just use plain JavaScript, you could use...

Edit: Adding Deparam Example:

 var DeparamExample = function() {
            var params = $.deparam.querystring();

            //nameofparam is the name of a param from url
            //code below will get param if ajax refresh with hash
            if (typeof params.nameofparam == 'undefined') {
                params = jQuery.deparam.fragment(window.location.href);
            }
            
            if (typeof params.q != 'undefined') {
                var paramValue = params.nameofparam.toString();
                  
            }
        };

If you want to just use plain JavaScript, you could use...

Fiex code colorization (was not the right language)
Source Link
A.L
  • 10.6k
  • 10
  • 73
  • 106
var getParamValue = (function() {
    var params;
    var resetParams = function() {
            var query = window.location.search;
            var regex = /[?&;](.+?)=([^&;]+)/g;
            var match;

            params = {};

            if (query) {
                while (match = regex.exec(query)) {
                    params[match[1]] = decodeURIComponent(match[2]);
                }
            }    
        };
    
    window.addEventListener
    && window.addEventListener('popstate', resetParams);

    resetParams();

    return function(param) {
        return params.hasOwnProperty(param) ? params[param] : null;
    }

})();​
var getParamValue = (function() {
    var params;
    var resetParams = function() {
            var query = window.location.search;
            var regex = /[?&;](.+?)=([^&;]+)/g;
            var match;
            
            params = {};
            
            if (query) {
                while (match = regex.exec(query)) {
                    params[match[1]] = decodeURIComponent(match[2]);
                }
            }    
        };
    
    window.addEventListener
    && window.addEventListener('popstate', resetParams);
    
    resetParams();
    
    return function(param) {
        return params.hasOwnProperty(param) ? params[param] : null;
    }
    
})();​
var getParamValue = (function() {
    var params;
    var resetParams = function() {
            var query = window.location.search;
            var regex = /[?&;](.+?)=([^&;]+)/g;
            var match;

            params = {};

            if (query) {
                while (match = regex.exec(query)) {
                    params[match[1]] = decodeURIComponent(match[2]);
                }
            }    
        };
    
    window.addEventListener
    && window.addEventListener('popstate', resetParams);

    resetParams();

    return function(param) {
        return params.hasOwnProperty(param) ? params[param] : null;
    }

})();​
var getParamValue = (function() {
    var params;
    var resetParams = function() {
            var query = window.location.search;
            var regex = /[?&;](.+?)=([^&;]+)/g;
            var match;
            
            params = {};
            
            if (query) {
                while (match = regex.exec(query)) {
                    params[match[1]] = decodeURIComponent(match[2]);
                }
            }    
        };
    
    window.addEventListener
    && window.addEventListener('popstate', resetParams);
    
    resetParams();
    
    return function(param) {
        return params.hasOwnProperty(param) ? params[param] : null;
    }
    
})();​
Added code colorisation
Source Link
A.L
  • 10.6k
  • 10
  • 73
  • 106
Loading
deleted 40 characters in body
Source Link
alex
  • 492.1k
  • 205
  • 890
  • 991
Loading
Post Made Community Wiki by Tomamais
deleted 1 characters in body
Source Link
alex
  • 492.1k
  • 205
  • 890
  • 991
Loading
added 659 characters in body
Source Link
alex
  • 492.1k
  • 205
  • 890
  • 991
Loading
added 2 characters in body
Source Link
alex
  • 492.1k
  • 205
  • 890
  • 991
Loading
added 354 characters in body
Source Link
alex
  • 492.1k
  • 205
  • 890
  • 991
Loading
added 170 characters in body
Source Link
alex
  • 492.1k
  • 205
  • 890
  • 991
Loading
deleted 7 characters in body
Source Link
alex
  • 492.1k
  • 205
  • 890
  • 991
Loading
Source Link
alex
  • 492.1k
  • 205
  • 890
  • 991
Loading