Getting url vars with javascript
I hope this little script can help you =)
I need to read some vars on the url, but, trying to write a portable function, so, i don’t know the variables name, obviusly later you can handler the names and the values of the vars:
<script type=”text/javascript”>
var URL = location.href;
URL = URL.replace(/.*\?(.*?)/,”$1”);
var params=URL.split(“&”);
var values = params.length;
var thevars = new Array();
for(i=0; i<values; i++)
{
keys = params[i].split(“=”);
thevars[keys[0]]=keys[1];
}
</script>
finally we got an array, the key is the var name and the content is the value ;) and then you can do something like that:
alert(“my var called wName: “+thevars[‘wName’]);