add_query_arg and get_query_arg functions in javascript

add_query_arg and get_query_arg functions in javascript

add_query_arg

function add_query_arg(purl, key,value){
    key = escape(key); value = escape(value);

    var s = purl;
    var pair = key+"="+value;

    var r = new RegExp("(&|\?)"+key+"=[^&]*");

    s = s.replace(r,"$1"+pair);
    //console.log(s, pair);
    if(s.indexOf(key + '=')>-1){


    }else{
        if(s.indexOf('?')>-1){
            s+='&'+pair;
        }else{
            s+='?'+pair;
        }
    }
    //if(!RegExp.$1) {s += (s.length>0 ? '&' : '?') + kvp;};

    return s;
}

get_query_arg


function get_query_arg(purl, key){
    if(purl.indexOf(key+'=')>-1){
        //faconsole.log('testtt');
        var regexS = "[?&]"+key + "=.+";
        var regex = new RegExp(regexS);
        var regtest = regex.exec(purl);
        //console.info(regtest);

        if(regtest != null){
            var splitterS = regtest[0];
            if(splitterS.indexOf('&')>-1){
                var aux = splitterS.split('&');
                splitterS = aux[0];
            }
            //console.log(splitterS);
            var splitter = splitterS.split('=');
            //console.log(splitter[1]);
            //var tempNr = ;

            return splitter[1];

        }
        //$('.zoombox').eq
    }
}

  • asasasasasa
    December 26, 2014 at 9:26 am

    asasas asasasas

  • asasasasasa
    December 26, 2014 at 9:26 am

    assasasasasasdsdsd

  • Nagendra babu Ganji
    January 28, 2015 at 11:41 am

    Thank you so much, this is what exactly im looking for.

  • zellina
    March 2, 2015 at 10:45 pm

    I really loved reading your blog. It was very well authored and easy to understand.
    http://www.toyotacarsstlouis.com

  • housecallhomecare
    March 26, 2015 at 7:27 pm

    For latest information you have to go to see world-wide-web and on world-wide-web I found this web site as a best website for hottest updates.

  • Simple Business Group
    June 1, 2015 at 10:26 pm

    You may post on the professional credentials for the blog owner. You could express it’s outstanding. Your blog experience can springboard your click through.

  • www.coolpetslive.com
    June 6, 2015 at 9:18 am

    Its very good and very exilant article. i really enjoyed this post and i hope you will keep posting this kinds of post in future.

  • sherwoodlakehomes
    June 9, 2015 at 5:59 pm

    I have subscribed to your rss feed which really should do the trick! Have a nice day!

Leave a comment

Your email address will not be published

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

35 + = 36