/ Published in: JavaScript
Usage:
Let's say we have an url: http://primera.vremenno.net?foo=yes&bar=no
var hash = getUrlVars();
alert(hash['foo']); // returns 'yes'
alert(hash['bar']); // returns 'no'
Let's say we have an url: http://primera.vremenno.net?foo=yes&bar=no
var hash = getUrlVars();
alert(hash['foo']); // returns 'yes'
alert(hash['bar']); // returns 'no'
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getUrlVars(){ var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++){ hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }