Search Scripts - Web Scripts Directory

Search Scripts - Web Development Scripts Directory

New Script Listings
New Scripts
Popular Scripts
Popular Scripts
Top Rated Scripts
Top Rated
Scripts Directory Search Engine
Search Scripts
Link to Scripts Directory
Link to Us
Search-Scripts Sitemap
Sitemap
PHP, AJAX, JavaScript, Perl, ASP Scripts Directory
Script Search Engine for Webmasters & Developers  
Search Scripts Home | Search Script Listings Become Sponsor | Information For Advertisers | Members Login Submit Script | Glossary of Scripts Glossary | About Search Scripts Directory About Search Scripts | Contact Us Contact Us | Sign Up Sign Up
 
Listing Title Get URL Querystring Parameters using Javascript  

Most of the server-side programming languages that I know of like PHP, ASP, or JSP give you easy access to parameters in the query string of a URL. Javascript does not give you easy access. With javascript you must write your own function to parse the window.location.href value to get the query string parameters you want. Here is a small function I wrote that will parse the window.location.href value and return the value for the parameter you specify. It does this using javascript's built in regular expressions. This JavaScript function reads a page's GET URL variables and return them. Here is the function:

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

The way that the function is used is fairly simple. Let's say you have the following URL:

http://www.foo.com/index.html?bob=123&frank=321&tom=213#top

You want to get the value from the frank parameter so you call the javascript function as follows:

var frank_param = gup( 'frank' );

Now if you look at the frank_param variable it contains the number 321. The query string was parsed by the regular expression and the value of the frank parameter was retrieved. The function is smart in a couple of ways. For example, if you have an anchor in your URL like our example URL above does (#top) the gup() function knows to stop before the # character. Also, if a requested parameter doesn't exist in the query string then an empty string is returned instead of a null.

This function has worked very well for my query string parsing needs and should work well for you.

Scripts Directory
Specifications Visit View Demo | Download Download
Platform(s) Linux, Windows, Mac OSX, Sun Solaris, FreeBSD
Database(s) None
Version 1
File Size < 100KB
Date Added Wednesday, October, 3rd 2007
Last Updated Wednesday, October, 3rd 2007
License Information
License Type Other Free / Open Source License
Price 0 USD
Resource Posted by: Archana Chadha. This script listing has been viewed 15422 times so far.
Search Scripts Disclaimer - Please be aware Search-Scripts.com accepts no responsibility for the scripts, components & software you are downloading. The same applies to the information provided about the Web Scripts, Tutorials & Software Products listed, as the producer can modify it without notifying us. Even if we try to check the files for viruses ourselves, we cannot guarantee 100% that they are clean. For your own protection always check downloaded files for viruses.
Click Here to view all the scripts in Tips and Tutorials category.
Rate it User Rating Chart
Rate Listing
Member Ratings - Chart
     
1 rating one ()
2 rating two ()
3 rating three ()
4 rating four ()
5 rating five ()
Visitor Ratings - Chart
() () () () ()
rating one rating two rating three rating four rating five
1 2 3 4 5
Review it Member Reviews
There are no user reviews for this Resource Listing. Be the first to post a comment. Click Here
Related Scripts Related Scripts
  1. Create new input controls and tables dynamically using JavaScript
Script Listing Information Additional Information
Script Number: 427
Rating: 0 out of 5 from votes
Rating Bar: No Rating
 
Script Listing Options Script Options
Print Script Print this Script Listing
Email Script Suggest to Friend by Email
Bookmark Script Listing
del.icio.us Bookmark del.icio.us Bookmark
Report for listing Report Listing
 
Search Scripts Search Scripts Directory
 
Partner Links
 
Webmaster Resources