JS parse URL and parameters

Source: Internet
Author: User
Tags object query return

js resolves URLs and parameters. The following code:

 
 
  1. <script language= "javascript" type= "Text/javascript" >
  2. var obj;
  3. Window.onload = function Getargs () {
  4. var args = new Object ();
  5. var query = location.search.substring (1); Get query string
  6. var pairs = Query.split ("&"); www.cxybl.com Break at Ampersand
  7. for (var i = 0; i < pairs.length; i++) {
  8. var pos = pairs[i].indexof (' = '); Look for "Name=value"
  9. if (pos = = 1) continue; If not found, skip
  10. var argname = pairs[i].substring (0, POS); Extract the name
  11. var value = pairs[i].substring (pos + 1); Extract the value
  12. Value = decodeuricomponent (value); Decode it, if needed
  13. Args[argname] = value; Store as a property
  14. }
  15. var ss = args.valueof (0);
  16. obj= args;
  17. return args; Return the object www.cxybl.com
  18. }
  19. function Test () {
  20. Used to hold all the property names and values
  21. var props = "";
  22. Start traversal
  23. For (var p in obj) {
  24. Method
  25. if (typeof (Obj[p]) = = "function") {
  26. Obj[p] ();
  27. } else {
  28. P is the property name, Obj[p] is the value of the corresponding property
  29. Props + + "=" + Obj[p] + "<br/>";
  30. }
  31. }
  32. All properties are displayed at the end
  33. return props;
  34. }
  35. </script>


Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.