[Tip]11.javascript How to get the parameters in the browser request address

Source: Internet
Author: User

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

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.