Click to See Complete Forum and Search --> : how to add Parsed values to a URL


polmsted
10-28-2003, 01:21 PM
I was wondering if anyone could help me.... I have found some code that will Parse out the URL if the link has ?blah=blah&blah=blah on it. I don't know how to encorporate that code so that it adds it onto a link so if the person goes to another page within the site, the ?blah=blah&blah=blah will stay with the url?

Here is the code I found to parse the URL:

<head>
<script>
function parseUrl()
{
var i, pos, argname, value, queryString, pairs;
// get the string following the question mark
queryString = location.search.substring(1);
// split parameters into pairs, assuming pairs are separated by ampersands
pairs = queryString.split("&");
// for each pair, we get the name and the value
for (i = 0; i < pairs.length; i++)
{
pos = pairs[i].indexOf('=');
if (pos == -1)
{
continue;
}
argname = pairs[i].substring(0,pos);
value = pairs[i].substring(pos+1);
alert("argname is " + argname + " and value is " + value);
}
}
</script>
</head>
<body onload="parseUrl();">

All I know is that I need to create a javascript link that if will attach the argname and value if it is there to the end of an href link so that those values remain. It is so we can track sponsors. Any way you can help?

Thank You,

Skip

agminer
10-28-2003, 08:55 PM
To me simple is good. If you are doing this within your site why not just make the url part of the link? If you are trying to track traffic from other sites they would have to code the url on their link.

polmsted
10-29-2003, 09:56 AM
That is exactly what we are doing. We attach a ?ref=blahblah
to a partners link. But we want to track them if they register. The problem is if they wonder around our site before they register, the ?ref=blahblah is lost. The code i found will parse the URL, now I need a way to add that variable to all the links within our site so we can track them as they move around the site. Our registrations sytem keeps track using JSP code, but that is on a different server and our website cannot use the same code. So I need to develope a javascript that will assign the variable to all links...

something like...

<script>
function gotopage(page, argname, value)
var page = ????

but what would go here?

</script>

link would be something like <a href="javascript:(pagename.html)">click here</a>

does that make sense?

agminer
10-29-2003, 03:53 PM
How about your href links use the onclick (acts as javascript) parse the incoming url for "attachments" asign attach to a var that the onclick appends to the out going url?

polmsted
10-29-2003, 04:22 PM
Im good with what ever works, my problem is I only know how to modify scripting, i don't know it well enough to write on my own. Could you give me a code example?

agminer
10-29-2003, 05:06 PM
try this

<a href="#" onclick='window.open( "yourpage.html?" +var_url_set_to_from_parse)'>clickhere</a>

watch your quotes (single/double) nest one inside other. Other wise if same quotes used throughout the program gets confused as to where to break things up.

polmsted
10-29-2003, 07:12 PM
that code doesn't work. href"#" takes you to a <a name="blah"></a> location on a webpage. so with your code example, it just takes me to the top of what ever page I happen to be on and disregards the onclick command.

There has got to be a code that will can use the values captured in the code i placed above and then attach them to a javascript var for the link.

<script>
function clicktolink(pagevariable)
var pagevarible=
window.open.('pagevariable' + 'argname' + 'value')
</script>

<a href="javascript: clicktolink('pagevariable.html')">Link 1</a>

<a href="javascript: clicktolink('pagevariable2.html')">Link 2</a>

agminer
10-29-2003, 07:27 PM
try this the href="#" and return false freeze the calling page
the focus brings the new page to the front

<a href="#" onclick='window.open( "yourpage.html?" +var_url_set_to_from_parse).focus();return false'>clickhere</a>