Jump to content
New Reality: Ads For Members ×

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!

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.

Archived

This topic is now archived and is closed to further replies.



×
×
  • 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.