toolman Posted August 20, 2015 Share Posted August 20, 2015 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! Quote Link to comment Share on other sites More sharing options...
dalecosp Posted August 26, 2015 Share Posted August 26, 2015 (edited) 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 August 26, 2015 by dalecosp Quote Link to comment Share on other sites More sharing options...
scootstah Posted August 27, 2015 Share Posted August 27, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.