JavaScript code: Change the link query parameter to name = Value

Source: Internet
Author: User
/**//*
* This function parses comma-separated name = value argument pairs from
* The query string of the URL. It stores the name = value pairs in
* Properties of an object and returns that object.
*/

Function getargs ()...{
VaR ARGs = new object ();
VaR query = location. Search. substring (1); // get query string.
VaR pairs = query. Split (","); // break at comma.
For (VAR I = 0; I <pairs. length; I ++ )...{
VaR Pos = pairs [I]. indexof ('='); // look for "name = value ".
If (Pos =-1) continue; // if not found, Skip.
VaR argname = pairs [I]. substring (0, POS); // extract the name.
VaR value = pairs [I]. substring (Pos + 1); // extract the value.
ARGs [argname] = Unescape (value); // store as a property.
// In JavaScript 1.5, use decodeuricomponent () instead of escape ()
}
Return ARGs; // return the object.
}

/**//*
* Example test. php? X = 1 & Y = 2 ....
*/
VaR ARGs = getargs (); // get arguments.
If (ARGs. X) x = parseint (ARGs. X); // If arguments are defined...
If (ARGs. Y) y = parseint (ARGs. Y); //... Override default values.
If (ARGs. W) W = parseint (ARGs. W );
If (ARGs. h) H = parseint (ARGs. H );
If (ARGs. dx) dx = parseint (ARGs. dx );
If (ARGs. Dy) dy = parseint (ARGs. Dy );
If (ARGs. interval) interval = parseint (ARGs. interval );

 

Related Article

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.