JAVASCRIPT[JS] Code _javascript tips for obtaining URL parameters

Source: Internet
Author: User
A recent page, you need to use JavaScript to get the URL parameters, can be found on the Internet, is more, the error is really much ah, really dizzy, wasted a lot of my time so, I will sum up, a good can be, the first statement, with regular, is simple, but the compatibility of multiple browsers, And speed is not guaranteed, so I use a browser-compatible
Copy Code code as follows:

<script language = javascript>
function request (paras) {
var url = location.href;
var parastring = url.substring (Url.indexof ("?") +1,url.length). Split ("&");
var paraobj = {}
for (i=0; j=parastring[i]; i++) {
Paraobj[j.substring (0,j.indexof ("=")). toLowerCase ()] = j.substring (j.indexof ("=") +1,j.length);
}
var returnvalue = Paraobj[paras.tolowercase ()];
if (typeof (returnvalue) = = "undefined") {
Return "";
}else{
Return returnvalue;
}
}
var theurl=request (' url ');
var theimg=request (' img ');
Document.writeln ("<a href=" "+ theURL +" ' target=_blank> ");
</script>

The main thing is to use the
Copy Code code as follows:

function request (paras) {
var url = location.href;
var parastring = url.substring (Url.indexof ("?") +1,url.length). Split ("&");
var paraobj = {}
for (i=0; j=parastring[i]; i++) {
Paraobj[j.substring (0,j.indexof ("=")). toLowerCase ()] = j.substring (j.indexof ("=") +1,j.length);
}
var returnvalue = Paraobj[paras.tolowercase ()];
if (typeof (returnvalue) = = "undefined") {
Return "";
}else{
Return returnvalue;
}
}

This function, later on the convenience, not everywhere to find the
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.