Get escaped URL parameter

后端 未结 19 2678
小蘑菇
小蘑菇 2020-11-21 13:41

I\'m looking for a jQuery plugin that can get URL parameters, and support this search string without outputting the JavaScript error: \"malformed URI sequence\". If there is

19条回答
  •  情书的邮戳
    2020-11-21 13:47

    For example , a function which returns value of any parameters variable.

    function GetURLParameter(sParam)
    {
        var sPageURL = window.location.search.substring(1);
        var sURLVariables = sPageURL.split('&');
        for (var i = 0; i < sURLVariables.length; i++)
        {
            var sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] == sParam)
            {
                return sParameterName[1];
            }
        }
    }​
    

    And this is how you can use this function assuming the URL is,

    "http://example.com/?technology=jquery&blog=jquerybyexample".

    var tech = GetURLParameter('technology');
    var blog = GetURLParameter('blog');
    

    So in above code variable "tech" will have "jQuery" as value and "blog" variable's will be "jquerybyexample".

提交回复
热议问题