Functions written in JavaScript For retrieving URL passing parameters on static pages

Source: Internet
Author: User

Previously I wrote about the function for jump menu positioning after the static page is refreshed. I had nothing to do with it a few days ago. It still seems a bit problematic and Its versatility is not good, so I wrote the following static page to obtain the function for passing URL parameters. By the way, the elements on the HTML page can not only use the default labels, but can be added by myself, for example: <input name = "infofileid" type = "hidden" gotourl = "#" id = "infofileid"> do you see the gotourl? It is convenient to use it directly. It is accidentally used when writing a function.

 

Function getquerystring (querystringname)
{
VaR returnvalue = "";
VaR urlstring = new string (document. Location );
VaR serachlocation =-1;
VaR querystringlength = querystringname. length;
Do
{
Serachlocation = urlstring. indexof (querystringname + "/= ");
If (serachlocation! =-1)
{
If (urlstring. charat (serachLocation-1) = '? ') | (Urlstring. charat (serachLocation-1) = '&'))
{
Urlstring = urlstring. substr (serachlocation );
Break;
}
Urlstring = urlstring. substr (serachlocation + querystringlength + 1 );
}

}
While (serachlocation! =-1)
If (serachlocation! =-1)
{
VaR seperatorlocation = urlstring. indexof ("&");
If (seperatorlocation =-1)
{
Returnvalue = urlstring. substr (querystringlength + 1 );
}
Else
{
Returnvalue = urlstring. substring (querystringlength + 1, seperatorlocation );
}
}
Return returnvalue;
}

 

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.