Methods for fetching URL parameters

Source: Internet
Author: User

varURLs = Window.location.search;//get the URL? The following path (parameter)functionUID (string) {if(String.IndexOf (' = ') < 0) {//use the IndexOf method to determine if there are no parameters behind the URL, that is, <0        return{};//returns an empty object to prevent an error} string= String.substr (String.IndexOf ('? ') + 1, string.length);//string assignment using the Substr method to intercept from? The last one begins, to the end    if(String.IndexOf (' # ') > 0) {//determine the URL after the # number is worth the situationstring = String.substr (0, String.IndexOf ("#"));//string Assignment intercept starts at 0 and ends at #    }    varobj = {},//defines the Obj object, the JSON object format, for storing the converted parameter objectPairs = String.Split (' & '),//define pairs = URL with & SplitD = decodeuricomponent;//the alias of the D decodeURIComponent method, which is called below$.each (Pairs,function(I, pair) {//use the each () methodPair = pair.split (' = ');//assigning a pair with an equal-value partition        varName = d (Pair[0]);//assign a value to name        varValue = d (pair[1]);//assigning values to valueObj[name] = value;//assigning a value to obj    }); returnObj//return the above resultsNote: The string here is not defined outside because it is defined internally and created automatically when needed (equivalent to local variables)

Methods for fetching 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.