0

I am setting up an affiliate link area for my site and need to be able to store a URL query string into a cookie that expires in a 7 days.

Users will click on a link like: http://examplesite.com?afil=randomvalue.

I want to pull the key 'afil' and the value 'randomvalue' and put it in a cookie in the browser.

This cookie will be used later (on another page) in a link from one of examplesite.com to order.examplesite.com but I can't keep the parameter (query string) in the URL.

I asked this last week and got an answer for using PHP: Add URL Parameter to Cookie

The problem is that I am using HubSpot and they don't allow me to use PHP code on the site.

I am hoping that they do permit Javascript or JQuery... so my questions are:

  1. How can I set a cookie from the URL query string using Javascript or JQuery?
  2. How can I call the value of said cookie to appear in a link using Javascript or JQuery?

I am hoping to find something similar to what they were trying to do here but this issue was never resolved: Set and check Javascript cookie based on url query string

Community
  • 1
  • 1
MattM
  • 3,089
  • 7
  • 40
  • 62
  • Possible duplicate of [How do I set/unset cookie with jQuery?](http://stackoverflow.com/questions/1458724/how-do-i-set-unset-cookie-with-jquery) – I wrestled a bear once. Jan 09 '17 at 18:47
  • you really waited a week for someone to tell you how to set a cookie instead of googling it and getting the answer instantly? cookies do not work that way anyway. you set a cookie on one domain it will not be visible on another page. took me about a quarter of a second to google this page for you by the way: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie – I wrestled a bear once. Jan 09 '17 at 18:48
  • I love sarcasm! But if you understood the question maybe you could supply an answer. I don't want the cookie to move from one site to another. I want to set a cookie and then use that cookie to create a link to another site, all on the same site. Also, I didn't wait a week. If you went to the page you would have seen that it was answered by someone who knows how to be helpful. – MattM Jan 09 '17 at 19:45
  • i could write a couple of lines of javascript to give you a cookie, but then what would you learn? you're clearly not interested in learning and just want someone to provide code for you. there are examples on the page i linked that you can copy from. seriously, we're not here to write your code for you. do a google search and make an attempt and if you can't get it, that's what we're here for. not to do it for you. – I wrestled a bear once. Jan 09 '17 at 19:49

0 Answers0