CoderZone.org

Category: >> JavaScript >> Read GET URL Variables Into An Associative Array. Bookmark and Share

<< lastnext >>

Snippet Name: Read GET URL Variables Into An Associative Array.

Description: This snippet read a page's GET URL variables and return them as an associative array.

Also see:
» Add a hidden field to a form dynam...
» SEO string generator
» Get the relative path to the root ...
» Match all #RRGGBB or #RGB values i...
» Add more fields to a form dynamica...
» Remove empty lines from a string o...
» Find first non-numeric character i...
» Get database and table sizes
» Get Unix Timestamp for midnight to...
» Get Easter Date for any year in Ja...
» Read a web page directly in to a s...
» Multi-line variables and strings i...
» Perl version of file_get_contents&...
» Get last and next months with ASP
» Get the URL of the referring page
» Convert a String to Title Case in ...
» Get all application variables
» Count all words in a string
» Count specific characters in a str...
» Get every 2nd (or 3rd, 4th, ...) e...
» Create an array from comma separat...
» Get Table Row Data On Click
» Convert Unix time string to a date...
» Find Symlink Targets
» Get File Size Over HTTP
» Get A Directory Listing Of Specifi...
» Getting Values Submitted From A Fo...
» A One-liner To Get Module Version
» Get Mouse Position Coordinates
» Get the computed style of an eleme...

Comment: (none)

Author: CoderZone
Language: JAVASCRIPT
Highlight Mode: HTML4STRICT
Last Modified: May 28th, 2010

// Read a page's GET URL variables and 
// return them as an associative array.
 
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;
}
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 23