Customizing Output Using Javascript URL Variables

Home arrow HTML & CSS Tutorials arrow Javascript arrow Customizing Output Using Javascript URL Variables
Customizing Output Using Javascript URL Variables Print E-mail
Contributed by Joe   
Friday, 28 July 2006

Output Using URL Variable Overview

When we need pass variable to another page,just like jsp or asp,we can add a series of name-value pairs to the end of the URL in the following form:

http://www.devx.biz/index.html?category=value1&item=value2&...

 

 

To extract URL parameters

In JavaScript, the document object provides the URL property that contains the entire URL for your document, and using some manipulation on this property, you can extract some or all of the URL parameters contained in the URL. The following code displays all URL parameters for the current document:

Use split method to separate the current document’s URL

var urlStr = document.URL.split(“?”);

Split the part of the URL to the right of the question mark into one
or more parts at the ampersand. This places each name-value pair
into an array entry in the parameterParts array.

var parameterParts = urlStr[1].split(“&”);

 See whole javascript url  example

 <script language=”JavaScript”>
var urlStr = document.URL.split(“?”);
var parameterParts = urlStr[1].split(“&”);
document.write(“<table border=1 cellpadding=3 cellspacing=0>”);
document.write(“<tr>”);
document.write(“<td><strong>Name</strong></td><td> <strong>Value</strong></td>”);
for (i = 0; i < parameterParts.length; i ++) {
document.write(“<tr>”);
var pairParts = parameterParts[i].split(“=”);
document.write(“<td>” + pairParts[0] + “</td>”);
document.write(“<td>” + unescape(pairParts[1]) + “</td>”);
document.write(“</tr>”);
}
document.write(“</table>”);
</script>

Last Updated ( Friday, 28 July 2006 )

  home              contact us

 

©2006-2012 DeveloperZone.biz   All rights reserved     powered by Mambo Designed by Siteground