|
-
Apr 22nd, 2004, 08:24 AM
#1
Parsing a querystring [Resolved]
I have a page, which will be called like so:
pagename.html?Referrer=PI
I need to use javascript to parse the querystring, and I simply need to check whether
Referrer = PP
Referrer = PI
or referrer simply isn't there.
This is the code I have, but it doesn't work.
Code:
<script language="javascript">
function querystring(key){
var value = null;
for (var i=0;i<querystring.keys.length;i++)
{
if (querystring.keys[i]==key)
{
value = querystring.values[i];
break;
}
}
return value;
}
querystring.keys = new Array();
querystring.values = new Array();
function querystring_parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");
for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
querystring.keys[querystring.keys.length] = argname;
querystring.values[querystring.values.length] = value;
}
}
}
querystring_parse();
x = querystring("Referrer");
//This is my main function, "goback", I'm trying to work with x
function goback(){
if x=="PP"{
document.location.href='page1.html';
}
else if x=="PI"{
document.location.href=page2.html';
}
else{
document.location.href=page3.html';
}
}
</script>
I am calling it like this:
Code:
<img src="brain.gif" onClick="javascript:goback();">
I'd appreciate any help. 
Edit: When I say "it doesn't work", it means I'm getting an error, "Object expected". That doesn't give me an idea as to what the problem is.
Last edited by mendhak; Apr 23rd, 2004 at 12:25 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|