Javascript get url parameters
Posted by Raj
Javascript get url parameters.
In this article, I will explain how to get url parameters in javascript.We are using following JavaScript code to get url parameters using javascript.I have written simple javascript function which will get a URL parameter and return it to you.
Suppose,My URL is http://example.com/pagename.html?a=1&b=2 and i want to
get parameters a=1,b=2
please check following code to Retrieve URL GET parameters with Javascript.
Example:getting URL parameters using Javascript
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>getting URL parameters using Javascript</title>
<script language="javascript">
getParameters();
function getParameters()
{
var url = window.location.href;//get an url
var splitUrl = url.split("?");
var splitparam = splitUrl[1].split("&");
var arrname = new Array();
var arrvalue = new Array();
var i = 0;
for (i=0;i<splitparam.length;i++){
var Param = splitparam[i].split("=");
arrname[i] = Param[0];
arrvalue[i] = unescape(Param[1]);
}
for (i=0;i<splitparam.length;i++)
{
alert(arrname[i]+" = "+ arrvalue[i]);//get url parameters
}
}
</script>
</head>
<body>
</body>
</html>
You can now get the current url parameters using the above code.I hope,this example will help you to get url parameters using JavaScript.
In this article, I will explain how to get url parameters in javascript.We are using following JavaScript code to get url parameters using javascript.I have written simple javascript function which will get a URL parameter and return it to you.
Suppose,My URL is http://example.com/pagename.html?a=1&b=2 and i want to
get parameters a=1,b=2
please check following code to Retrieve URL GET parameters with Javascript.
Example:getting URL parameters using Javascript
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>getting URL parameters using Javascript</title>
<script language="javascript">
getParameters();
function getParameters()
{
var url = window.location.href;//get an url
var splitUrl = url.split("?");
var splitparam = splitUrl[1].split("&");
var arrname = new Array();
var arrvalue = new Array();
var i = 0;
for (i=0;i<splitparam.length;i++){
var Param = splitparam[i].split("=");
arrname[i] = Param[0];
arrvalue[i] = unescape(Param[1]);
}
for (i=0;i<splitparam.length;i++)
{
alert(arrname[i]+" = "+ arrvalue[i]);//get url parameters
}
}
</script>
</head>
<body>
</body>
</html>
You can now get the current url parameters using the above code.I hope,this example will help you to get url parameters using JavaScript.
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
current page name,
get an url,
get parameter from url,
get parameters from url,
get url parameter,
get url parameters,
getting url,
JAVASCRIPT,
jquery get url parameters,
location path name
.You can leave a response, or trackback from your own site.