Posted By

cliffpyles on 10/27/11


Tagged


Versions (?)

jQuery.hrefToObject.js


 / Published in: Other
 

  1. var hrefToObject = function (linkElementArg) {
  2. var href = {
  3. base: '',
  4. parameters: {},
  5. toString: function () {
  6. var hrefString = this.base + '?';
  7. var pCounter = 0;
  8. for (p in this.parameters) {
  9. var parameter = this.parameters[p];
  10. if (pCounter != 0) {
  11. hrefString += '&' + p + '=' + parameter;
  12. } else {
  13. hrefString += p + '=' + parameter;
  14. }
  15. pCounter++;
  16. }
  17. return hrefString;
  18. }
  19. };
  20. var hrefLink = $(linkElementArg).attr('href'); //href value of link provided
  21. var hrefQuery = hrefLink.split('?'); //query appended the the href URL
  22. var hrefPairs = hrefQuery[1].split('&');
  23. href.base = hrefQuery[0];
  24. for (var h in hrefPairs) {
  25. var pair = hrefPairs[h].split('=');
  26. href.parameters[pair[0]] = pair[1];
  27. };
  28. return href;
  29. }

Report this snippet  

You need to login to post a comment.