JS get parameters, in the past I was used to split, and then get, this way feeling is the simplest
Mode 1:
function QueryString (item) { var svalue=location.search.match (new RegExp ("[\?\&]" +item+ "= ([^\&]*) (\&?)", "I")) return svalue?svalue[1]:svalue}// Use method //url=http://www.xxx.com?id=100&name=domvar id=querystring ("ID" ); var name=querystring ("name");
In this way, every time you call QueryString () This method will parse the URL once (of course, many parameters of the case will not be slow to parse)
Mode 2:
functiongetrequest () {varurl = location.search;//gets the URL in the "?" String after the character varTherequest =NewObject ();//put parameters into this object if(Url.indexof ("?")! =-1) { varstr = URL.SUBSTR (1); STRs= Str.split ("&"); //Storage Parameters for(vari = 0; i < strs.length; i + +) {Therequest[strs[i].split ("=") [0]]= (Strs[i].split ("=") [1]); } } returntherequest; }//How to use varRequest =NewObject (); Request=getrequest (); //url--http:www.xxx.com?id=1&&kid=2 varid=requesr["id"];
This way the parameters are stored in one object at a time, and the URL is parsed again when the argument is taken.
Two ways to get URL parameters for JS