Output Using URL Variable OverviewWhen 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 parametersIn 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> |