Jump to content

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!

I might use PHP to set the cookie, because JavaScript is a tad clunky where cookies are concerned, so if I can do it in server-side, I almost always do.

Can you do it server-side?

 

Edited by dalecosp

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.

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.