varGetaccessparams =function(){ varI,ilen,strs,keyname,keyvalue, params={}, Path=window.location.pathname, url=window.location.href; if(Url.indexof ("?") >-1){ varIndex=url.indexof ("?")); STRs=url.substring (index+1); //Console.log (STRs);Strs=strs.split ("&"); Ilen=strs.length; for(i=0;i<ilen;i++){ varIndexequal=strs[i].indexof (' = ')); KeyName=strs[i].substring (0, indexequal); KeyValue=strs[i].substring (indexequal+1); if(keyname== "callback") keyvalue=decodeuricomponent (KeyValue); Params[keyname]=KeyValue; } } returnparams; }; //Console.log (Getaccessparams ());
The request address is: Http://localhost:8001/shxt_web/chanjet/js/test_whuang.html? Callback=http://www.weixin.com?id=123&app=weixin
, the result of the operation is:
Object {callback: "Http://www.weixin.com?id=123", App: "Weixin"}
http://localhost:8001/shxt_web/chanjet/js/test_whuang.html?callback=http://www.weixin.com?id=123&app= Weixin&returnurl=http://www.baidu.com
Operation Result:
Object {callback: "Http://www.weixin.com?id=123", App: "Weixin", ReturnUrl: "Http://www.baidu.com"}
Note I here callback is fixed value, can feel my here continue to modify, eliminate their own requirements to fix, feel this is still very useful!
I still insist on the programmer's path, is correct!
[Tip]11.javascript How to get the parameters in the browser request address