Get the Address bar URL in the parameters, Getquerysting () method

Source: Internet
Author: User

The previous get URL address parameter used by colleagues today is not available. The previous method failed. A regular expression bug was found later:

The first method of acquisition (generally sufficient for general conditions):

 function getquerystring (name) {var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)", "I");    var reg_rewrite = new RegExp ("(^|/)" + name + "/([^/]*) (/|$)", "I");    var r = window.location.search.substr (1). Match (REG);    var q = window.location.pathname.substr (1). Match (Reg_rewrite);    if (r! = null) {return unescape (r[2]);    }else if (q! = null) {return unescape (q[2]);    }else{return null; }} 
The second method of getting:
The URL address is not getting: file:///Users/wanghong/work/ziku/youle/dist/index.html?sourceType=Tsingtao_beer _activity#/welcome?topath=file%3a%2f%2f%2fusers%2fwanghong%2fwork%2fziku%2fyoule%2fdist%2findex.html% 3FSOURCETYPE%3DTSINGTAO_BEER_ACTIVITY%23%2F
/** * Gets the specified URL parameter value * url:http://www.quwan.com/index?name=tyler * parameter: paramname URL parameter * Call method: GetParam ("name") * return value: Tyler */f Unction GetParam (paramname) {    paramvalue = "", Isfound =! 1;    if (This.location.search.indexOf ("?") = = 0 && this.location.search.indexOf ("=") > 1) {        Arrsource = Unescape (This.location.search). substring (1, this.location.search.length). Split ("&"), i = 0;        while (I < arrsource.length &&!isfound) arrsource[i].indexof ("=") > 0 && arrsource[i].split ("=") [ 0].tolowercase () = = Paramname.tolowercase () && (paramvalue = arrsource[i].split ("=") [1], isfound =!0), i++    }    return paramvalue = = "" && (paramvalue = null), paramvalue}

Let's have a try. Happy Lantern Festival

Get the Address bar URL in the parameters, Getquerysting () method

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.