Question

I run a blog (in blogger/blogspot). I need help placing a cookie on a visitors computer. Also I need help on placing information on that certain cookie. To be more exact of what I want to do. When a visitor clicks an external link (api.viglink) a cookie is placed with some info in it. How can I place my own cookie with the info that I want in it?? Please be descriptive with your solutions. Not just code

Was it helpful?

Solution

If you are able to run JavaScript:

function setcookie(name, value, exp) {
var today = new Date();
var expires = new Date();
var ndays = 1;
var path = '/';
var domain = 'yourdomain.blogger.com';
var secure = false;
var val = escape(value) || "";
exp = (exp == -1) ? true : false;
if (exp) {
    expires.setDate(today.getDate() - 1)
} else {
    if (ndays == null || ndays == 0) ndays = 1;
    expires.setTime(today.getTime() + 3600000 * 24 * ndays)
};
document.cookie = name + "=" + val + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "")
}

OTHER TIPS

function setCookie(c_name,value,exdays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : ";
    expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

Copied from LINK

You pass the values you have into the variables of the function. Remember that the only required information needed to create a cookie is the name/value pair.

Something like:

document.cookie = "name=value;" + "expires=Sat, 16 May 2009 18:40:22 GMT";[1]

This is also how you can set a cookie. I hope I am answering your questions.

Steve

[1] http://www.thonky.com/javascript-and-css-guide/set-cookie/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top