Forum Moderators: open

Message Too Old, No Replies

Capture query string in cookie and append to URL

         

andrewg 1976

2:12 am on May 30, 2007 (gmt 0)

10+ Year Member



Hi,

Can anyone tell me if this is possible and if yes the code I could use to do it?

Say a visitor comes to my website using the following URL: [mywebsite.com...]

I want to capture the query string "cid=1234" and store it in a session cookie, then when the visitor clicks on a link on my page (index.html) to an external site, ie. to [externalsite.com...] I want to append the query string stored in the cookie to the URL, so it will become [externalsite.com...]

Thanks,
Andrew

colandy

1:22 pm on Jun 4, 2007 (gmt 0)

10+ Year Member



To obtain the query string use the following:

qstring=document.location.href.split('?')[1];

eg... if [sitename.com...]

qstring will be "for=1&top=7"

Dont use cookies so don't know how to store into cookies in JS and I'm sure you know how to add to a link.

Arno_Adams

11:19 am on Jun 5, 2007 (gmt 0)

10+ Year Member



Hi,

alternatively use location.search.substring(1)
to capture the querystring.

HTH, AA

andrewg 1976

4:54 am on Jun 7, 2007 (gmt 0)

10+ Year Member



Thanks!

location.search.substring(1) does the trick!