Skip to content

Instantly share code, notes, and snippets.

@rdbox
Created April 17, 2016 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdbox/11923cd1497feac3012d9d5f9d954d1d to your computer and use it in GitHub Desktop.
Save rdbox/11923cd1497feac3012d9d5f9d954d1d to your computer and use it in GitHub Desktop.
/*Данный код дает возможность добавлять и читать куки*/
function set_cookie(name, value, expires, path, domain, secure) {
var cookie_string = name + "=" + escape(value);
if (typeof expires == 'number' && expires > 0) {
var d = new Date();
var n = new Date(d.setTime(d.getTime() + expires * 1000));
expires = n.toUTCString();
cookie_string += "; expires=" + expires;
}
if (path) {
cookie_string += "; path=" + escape(path);
} else {
cookie_string += "; path=/";
}
if (domain)
cookie_string += "; domain=" + escape(domain);
if (secure)
cookie_string += "; secure";
document.cookie = cookie_string;
}
function get_cookie(name) {
var cookie = " " + document.cookie;
var search = " " + name + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset);
if (end == -1) {
end = cookie.length;
}
setStr = unescape(cookie.substring(offset, end));
}
}
return (setStr);
}
function delete_cookie(name) {
var expires = new Date();
expires.setTime(expires.getTime() - 1);
document.cookie = name += "=; expires=" + expires.toGMTString();
}
if (!get_cookie("prometriki")) {
//alert("нету значения в куках");
var prometriki = 'filter';
if ("prometriki") {
jQuery(document).ready(function($) {
$('body').append(location.href + prometriki);
});
jQuery(document).ready(function($) {
$('body').append('</br><a href=\'javascript:set_cookie("prometriki", prometriki );document.location.reload ( )\'>Добавить Куки</a></br>');
});
}
} else {
var prometriki = get_cookie("prometriki");
jQuery(document).ready(function($) {
$('body').append('</br><a href=\'javascript:delete_cookie("prometriki");document.location.reload();\'>Удалить куки</a></br>');
});
jQuery(document).ready(function($) {
$('body').append('Адрес URL: ' + location.href + 'prometriki');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment