This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/scripts/functions/fonctions_annexes/cookiesManagement_Functions.js

34 lines
952 B
JavaScript

/**
* @function createSessionCookie
* @description Créer un cookie de session.
* @param {string} name Nom du cookie
* @param {string} value Valeur du cookie
*/
function createSessionCookie(name, value) {
document.cookie = escape(name) + "=" + escape(value) + " ; path=/";
}
/**
* @function getCookieValue
* @description Récupère la valeur d'un cookie.
* @param {string} name Nom du cookie
* @param {string} value Valeur du cookie
*/
function getCookieValue(cname) {
const name = cname + "=";
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
/* Exports */
export { createSessionCookie, getCookieValue };