Skip to content


Reading Parameters from URL using JavaScript

This section contains a lot of Scripting material for your website.

Reading Parameters from URL using JavaScript

Postby Web Guru » December 14th, 2008, 1:11 pm

Reading parameters from URL in javascript is not a tough task, its very simpleif you know some of the basic javascript functions and document.location object properties.

- First get the url parameters from the document.location object as follows:
Code: Select all
  var Params = document.location.search.substring(1);


- Now you can parse the parameters using the .split() function as follows:
Code: Select all
  Params = Params.split('&');


- Now you have all the url parameters in the form of key=value pair in the "Params" array.

- You can further process this array as per your needs.

The complete code is as follows:
Code: Select all
  var Params = document.location.search.substring(1);
  Params = Params.split('&');
 
  var Count  = Params.length;

  var Parameters = array( );

  for (i = 0; i < Count; i ++)
  {
    var Temp = Param[i].split("=");

    Parameters[i] = array(2);
    Parameters[i][0] = Temp[0]; // Key
    Parameters[i][1] = Temp[1]; // Value
  }


- Now you can enjoy your erest of the work with the "Parameters" array.
User avatar
Web Guru
 
Posts: 94
Joined: March 24th, 2008, 7:59 am
Location: Lahore, Pakistan

Return to Board index

Return to Java Script / VB Script

Who is online

Users browsing this forum: No registered users and 0 guests