Forum Moderators: open

Message Too Old, No Replies

writing query string to page links

         

badjo

6:39 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



I am trying to adjust a script and looking for a little help.

First what I am trying to do is to grab a url query and write it to the links on the landing page so if any of the links get clicked on the query goes with it.

There are a few query grabbing links around but I can not get them to write to the page.

Here is an example:

visitor comes to my site from this link:
www.domain.com?id=1234

The page they land on has several links on it:
faq.html?(i_want_the_id_inserted_here 1234)
benefits.html?(i_want_the_id_inserted_here 1234)
help.html?(i_want_the_id_inserted_here 1234)
etc.

Below are a few scripts I was trying to work with but I was hoping someone could add to them so they would write to my links as I demonstrated above.

<script type="text/javascript">
querystring = location.search.substring(1);
</script>

if (location.search.length > 0) {
launchString = location.search.substring(1, location.search.length);
var launchStringArray = launchString.split("&");
for (var i = 0; i <= launchStringArray.length - 1; i++) {
var left = launchStringArray[i].substring(0, launchStringArray[i].indexOf("="));
var right = launchStringArray[i].substring(launchStringArray[i].indexOf("=") + 1, launchString.length);
if (isNaN(right)) {
right = '"' + right + '"';
}
eval("var " + left + " = " + right);
}
}

I have tried with no success so I hope someone is in the charity mood and can figure this out.

Thanks for any help

John

prasanth

9:32 am on Jun 10, 2005 (gmt 0)

10+ Year Member



The first query string you can get with
location.href.split("?")[1].split("=")[1];

badjo

11:52 am on Jun 10, 2005 (gmt 0)

10+ Year Member



Thanks! I got it. This will capture the query and append to the links on a page.

</HEAD>
<BODY>

<script language="javascript">
function linkWithQuery(url,txt)
{
return "<a href=\"" + url + location.search + "\">" + txt + "</a>"
} // linkWithQuery
</script>
<script language="javascript">
document.write(linkWithQuery("http://www.yahoo.com/more.html","<img src='/images/select.gif' border='0' alt='Select'>"))
</script>