ClanKiller.com
https://forums.plasmasky.com/

a handy javascript function for getting GET vars
https://forums.plasmasky.com/viewtopic.php?f=24&t=2167
Page 1 of 1

Author:  Satis [ Thu Jan 18, 2007 7:41 am ]
Post subject:  a handy javascript function for getting GET vars

hey, I found this online somewhere and thought I'd share. I make prolific use of GET vars where it makes sense (you can bookmark a GET, after all), and I make prolific use of javascript for AJAX, but getting a GET var with javascript can be a pain. This function does it for you.

[php]
function gup(name){
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var tmpURL = window.location.href;
var results = regex.exec( tmpURL );
if( results == null )
return "";
else
return results[1];
}
[/php]

just pass it the name of the var you want and it'll send back the value. VERY handy.

[php]
function whatever(){
document.getElementById('PigIsTheCoolest').innerHTML = gup('PigGetVar');
}
[/php]

Author:  Pig [ Thu Jan 18, 2007 12:12 pm ]
Post subject: 

I just do this:
Code:
function qs2get(){
   $_GET = new Array;
   var $parameters = location.search.substring(1).split('&');
   for( var $i = 0; $i < $parameters.length; $i++ ) {
      var $pos = $parameters[$i].indexOf('=');
      if ($pos > 0){
         var $key = $parameters[$i].substring(0,$pos);
         var $value = $parameters[$i].substring($pos+1);
         $_GET[$key] = $value;
      }
   }
}

qs2get();
alert($_GET['nipple_clamp']);


JS's handling of cookies and get data is just retarded.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/