JS Processing URL Parameters

Source: Internet
Author: User
Tags hasownproperty

var urlargent = {Parsed:false,//whether the cache has been resolved: {},//Cached value parsearg:function () {                Resolves the parameter value of the Address bar urlargent.parsed = true;                var url = location.search;                if ( -1 = = Url.indexof ('? ')) return;                var args = url.substr (1). Split ("&");                    for (var i = 0; i < args.length; i++) {var tmp = args[i];                    var pos = tmp.indexof (' = ');                    if ( -1 = = pos) continue;                Urlargent.cache[tmp.substr (0, pos)] = TMP.SUBSTR (pos + 1); }}, Getitem:function (Querystringname, Defaultval) {//Gets the value of a single item querystringname size                Write sensitive, and case sensitive if (urlargent.parsed = = False) Urlargent.parsearg (); return Urlargent.cache[querystringname] | | (typeof (Defaultval) = = ' undefined '?            ": defaultval.tostring ()); }, Getitemignore:function (QUERYSTRINGNAme, Defaultval) {//Gets the value of a single item querystringname ignores case if (urlargent.parsed = = False) Urlargen                                T.parsearg ();                    For (var k in Urlargent.cache) {if (UrlArgent.Cache.hasOwnProperty (k) = = false) continue;//take private property only                if (k.tolowercase () = = Querystringname.tolowercase ()) return urlargent.cache[k]; } return (typeof (defaultval) = = ' undefined '?            ": defaultval.tostring ()); }, Geturl:function (NewValue, ignore) {///Get URL parameter NewValue added or modified value ignore keyword ignores case, true ignores case He values case sensitive if (typeof (NewValue)! = ' object ') return Location.search.substr (1);                returns if (urlargent.parsed = = False) Urlargent.parsearg ();                var url = [];                    For (var k in Urlargent.cache) {if (UrlArgent.Cache.hasOwnProperty (k) = = false) continue;//take private property only var val = urlargent.cache[K]; The default is the original value for (var n in newvalue) {if (Newvalue.hasownproperty (n) = = False) Conti                        Nue if (k = = N) | | (Ignore = = True && k.tolowercase () = = N.tolowercase ()))  {//need to replace the original value val = newvalue[n].tostring ();//Assign new value newvalue[n] = null;                Clears the value-setting}} url.push (k + ' = ' + val);                    } for (var n in newvalue) {//new added key value if (Newvalue.hasownproperty (n) = = false) continue;                    if (newvalue[n] = = null) continue;                Url.push (n + ' = ' + newvalue[n].tostring ());            } return Url.join (' & '); }        };

Use:

        var a = Urlargent.getitem (' x ');        var x = Urlargent.getitem (' x ', 0);        var y = urlargent.getitemignore (' X ');        var s = urlargent.geturl ();        var w = urlargent.geturl ({"X": "VV", "IsMobile": "vs"});        var z = urlargent.geturl ({"X": "VV", "IsMobile": "vs"}, true);

JS Processing URL Parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.