ClanKiller.com https://forums.clankiller.com/ |
|
a handy javascript function for getting GET vars https://forums.clankiller.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: | |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |