Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get url parameter using jquery or plain javascript

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 typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
        }
    }
    return false;
};
And this is how you can use this function assuming the URL is,
http://dummy.com/?technology=jquery&blog=jquerybyexample.

var tech = getUrlParameter('technology');
var blog = getUrlParameter('blog');
Comment

get param 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 typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
        }
    }
    return false;
};
Comment

jquery get parameter from url

 
(function($) {
    $.QueryString = (function(a) {
        if (a == "") return {};
        var b = {};
        for (var i = 0; i < a.length; ++i)
        {
            var p=a[i].split('=');
            if (p.length != 2) continue;
            b[p[0]] = decodeURIComponent(p[1].replace(/+/g, " "));
        }
        return b;
    })(window.location.search.substr(1).split('&'))
})(jQuery);
 
// Usage
var param = jQuery.QueryString["param"];
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript copy array 
Javascript :: array fill 
Javascript :: make button inside datatable 
Javascript :: variable used in a function can be used in another function js 
Javascript :: how to concat nested array in javascript 
Javascript :: node js send javascript 
Javascript :: bson to json converter 
Javascript :: vue 3 create component 
Javascript :: sum of odd numbers in an array javascript without loop 
Javascript :: how to check if the element exist in the parent element javascript 
Javascript :: Uncaught TypeError: $(...).jstree is not a function 
Javascript :: upload file angular 
Javascript :: Hide angular element on button click 
Javascript :: usememo react 
Javascript :: what does getattribute return null for data-* attributes 
Javascript :: javascript replace spaces with br 
Javascript :: jquery get all classes of a div 
Javascript :: execcommand js 
Javascript :: fetch from vscode 
Javascript :: reverse keys and values in object javascript 
Javascript :: find element by object field vuejs 
Javascript :: javascript copy value to clipboard 
Javascript :: node mac copy to clipboard 
Javascript :: stopwatch with javascript 
Javascript :: react key press hook 
Javascript :: javascript bind this to anonymous function 
Javascript :: local storage react 
Javascript :: add google analytics to react 
Javascript :: react eslint prettier 
Javascript :: Connect to socket.io node.js command line 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =