Posted By

damarev on 07/17/06


Tagged


Versions (?)

Who likes this?

12 people have marked this snippet as a favorite

meth
jkochis
rolandog
Leech
powerkan
raws
SpinZ
jeremyhcobb
KyleFarris
seanpowell
guo3823538
wirenaught


get URL Params (2 methods)


 / Published in: JavaScript
 

  1. var Url = location.href;
  2. Url = Url.replace(/.*\?(.*?)/,"$1");
  3. Variables = Url.split ("&");
  4. for (i = 0; i < Variables.length; i++) {
  5. Separ = Variables[i].split("=");
  6. eval ('var '+Separ[0]+'="'+Separ[1]+'"');
  7. }
  8.  
  9.  
  10.  
  11. function getURLParam(strParamName){
  12. var strReturn = "";
  13. var strHref = window.location.href;
  14. if ( strHref.indexOf("?") > -1 ){
  15. var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
  16. var aQueryString = strQueryString.split("&");
  17. for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
  18. if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
  19. var aParam = aQueryString[iParam].split("=");
  20. strReturn = aParam[1];
  21. break;
  22. }
  23. }
  24. }
  25. return strReturn;
  26. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: KyleFarris on April 23, 2009

Great code. Thanks.

Posted By: KyleFarris on April 23, 2009

Great code. Thanks.

You need to login to post a comment.