How to access URL parameters in Javascript

Source: Internet
Author: User

// Get URL parameters
// Return a specialized Param Value
Function geturlparameters (paramname)
{
Try
{
VaR Surl = (registry.doc ument. url. tostring ());

// Alert (Surl );

If (Surl. indexof ("? ")> 0)
{
VaR arrparams = Surl. Split ("? ");

VaR arrurlparams = arrparams [1]. Split ("&");

VaR arrparamnames = new array (arrurlparams. Length );
VaR arrparamvalues = new array (arrurlparams. Length );

VaR I = 0;
For (I = 0; I <arrurlparams. length; I ++)
{
VaR sparam = arrurlparams [I]. Split ("= ");
Arrparamnames [I] = sparam [0];
If (sparam [1]! = "")
Arrparamvalues [I] = Unescape (sparam [1]);
Else
Arrparamvalues [I] = "undefined ";
}

For (I = 0; I <arrurlparams. length; I ++)
{
// Alert (arrparamnames [I] + "=" + arrparamvalues [I]);
If (arrparamnames [I] = paramname. tostring ())
{
Return arrparamvalues [I];
}


}
}
Else
{
Return "undefined ";
}
}
Catch (E)
{
Return NULL;
}
}

 

// Transfer XML by URL parameters
// Location. href = "frmpenaltyinvoice. aspx? PID = create & xml = "+ escape (XML );

 

 

 

// By URL string // var xml = geturlparameters ("XML"); // This having max parameter size limited // with browser (ie, Firefox ...)

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.