Append url based on cookie

Hi,

I have a URL which is something like: http://www.website.com/page.shtml?ref=code1

This page loads a cookie with a value of “code1”. What I would like to do is to add the part ref=code1 to a link on an image, for example: <a href="http://www.newwebsite.com?ref=code1"><img src="image.png" /></a>

How would I do this using jQuery?

Thanks

EDIT
This post has been reformatted by enclosing the inline code with backticks
`
before and after the code.

You can use jquery.cookie plugin.

Your code will looks like:

$(document).ready(function(){
    var cookieValue = $.cookie("cookie_name");
    var linkSrc = $('#my_link').attr("src");
    $('#my_link').attr("src", linkSrc + "?ref=" + cookieValue);
});
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.