Jump to content

set cookie and replace image based on URL


toolman

Recommended Posts

Hi,

 

I am wanting to set a cookie based on a dynamic URL, e.g http://www.website.com/?ref=cookieval

 

I then want to replace an image on the page with an image using the name of the cookie, e.g <img src="/images/cookieval.png" />

 

How would I do this? I think I can use

 

$(".banner").html("<img src="/images/cookieval.png");

 

But I don't know how to set the cookie from the URL and then use it in the jQuery .html() part.

 

Any ideas how I would do this?

 

Thanks!

Link to comment
Share on other sites

https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie

https://developer.mozilla.org/en-US/docs/Web/API/Window/location

 

Here is relevant documentation for what you want. The first is about cookies, and the second is about window.location which is what you use to get the query string. Specifically, you want the search property, window.location.search.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.