Instance code: js obtains url parameters to change the Website access address

Source: Internet
Author: User

Recently, a friend has been asking questions about css and JS when revising a website. Today, this friend asked me again about the link to the revised website, because the original website URLs are directly linked, and cannot be accessed after the revision, this will cause a loss to the website and a lot of traffic will disappear. If you use JS to turn around, how nice it is! This idea is good, so I told my friends that I needed an html page to pass parameters, so I used JavaScript code to get url parameters, retrieve the url parameter of a js and change the Website access address funciton to an instance:

  URL type after redirection:Http://www.bkjia.com/url.htm? Url = http://www.liehuo.org

  JS Code:

<Script language = "javascript" type = "text/javascript">
// Js obtains the function of the url parameter
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
Theurl = request ("url ");
If (theurl! = ''){
Location = theurl
}
</Script>

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.