Click here to Skip to main content
Licence 
First Posted 8 Aug 2004
Views 138,190
Bookmarked 24 times

Getting URL parameters using JavaScript

By | 8 Aug 2004 | Article
An article on getting URL parameters using JavaScript (IE, NS).

Sample Image

Introduction

This is a JavaScript that helps you get the URL Parameters of a page..

Using the code

It's very easy to use the script. Just include the .js file into the page HTML code and execute it when you want.

<script language="javascript" src="scripts/getParams.js"></script>

The getParams.js, which is saved in the "scripts" folder in the project, includes the function getURLParameters() which splits the URL string after the first '?' character, and it puts the parameter names and values in separate arrays, which have the same length.

If no parameters are found in the URL string, the appropriate alert comes up.

Finally, I have configured the script in such a way, that if a parameter does not have any value, the alert that shows this parameter, displays "No value" for this parameter.

At the end, the function shows the parameter names and values one by one, in alert message boxes, as it is shown in the picture above.

Points of Interest

I was wondering if it is possible to use URL parameters in client only pages, because it is useful sometimes to handle information and data by this way.

So, I learned how to get the URL parameters of a web page by using only JavaScript and not any Server-Side programming language.

The script can be used in both Internet Explorer and Netscape browsers.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

stribroboy

Web Developer

Greece Greece

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralA Little More Useful Code Pinmemberpiles7:29 18 May '09  
GeneralAlternative 'complete' argument splitter that supports objects, arrays and other stuff Pinmemberarc20007:59 7 Nov '08  
Generalit is not complete Pinmemberbreceivemail21:45 7 Jun '08  
GeneralRe: it is not complete PinmemberBizounours3:07 7 Oct '08  
GeneralExistParameter ( Param ) GetParameterValue ( Param ) Functions added PinmemberRicardo Casquete5:45 11 Sep '06  
GeneralUseful PinmemberRicardo Casquete4:20 11 Sep '06  
GeneralGood job Pinmemberjohnacruise13:25 23 Aug '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 9 Aug 2004
Article Copyright 2004 by stribroboy
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid