Forum Moderators: open

Message Too Old, No Replies

Capturing Query String

Put in existing cookie?

         

Mardi_Gras

7:37 pm on Jan 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks to help from mipapage and bunltd, I have implemented a script to capture referral strings in a cookie and pass them through to my e-mail submission form.

Since many of these leads are coming through paid advertising, I would like to capture the query string of the URL they click on as well. I would prefer to store everything in one cookie.

Any ideas on how to capture the query string? Ideally, into the cookie that is already being created with the referral string?

The query string is in my logs but correlating logs with e-mails is too time consuming to bother with. Expert advice appreciated - I am a cookie novice.

DrDoc

12:20 am on Jan 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To capture the query string...

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

...then you can do whatever you want with it.

timware

2:22 am on Feb 20, 2004 (gmt 0)

10+ Year Member



Hello,

I just sort of stumbled on your message while trying to do exactly what you said you had done with the help of mipapage. I want to have a javascript that captures the referral strings in a cookie and I can insert that value into a form. Would you mind passing that info along to me?

I suppose I'll have to run the script on every page as I won't know in advance which page of my site the user will hit first, as it's not always the home page.

Thanks.

Tim

Purple Martin

4:51 am on Feb 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a script I wrote ages ago that will parse any search string and automatically declare all search parameters as JavaScript variables with values. It handles both numeric and string variable types correctly. It might be useful to you. Put it right at the top of the document head.

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);
}
}

timware

6:19 am on Feb 20, 2004 (gmt 0)

10+ Year Member



Well, thanks for this. Excuse my ignorance, but how do I actually implement this? Or use it? Thanks. Tim