Skip to content

Instantly share code, notes, and snippets.

@Johnbug
Created September 5, 2013 05:34
Show Gist options
  • Save Johnbug/6446399 to your computer and use it in GitHub Desktop.
Save Johnbug/6446399 to your computer and use it in GitHub Desktop.
原生JavaScript设置cookie值
function setCookie(name, value, Hours) {
var d = new Date();
var offset = 8;
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var nd = utc + (3600000 * offset);
var exp = new Date(nd);
exp.setTime(exp.getTime() + Hours * 60 * 60 * 1000);
document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString() + ";domain=360doc.com;"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment