javascript - Jquery very tasty Cookie -


i have code sets cookie every folder of domain (for example, domain.com , domain.com/folder, domain.com/folder2) have same cookie name ("history") , different "history" values. how can ignore path cookie , add cookie value in same name ("history") if cookie set folder? used standart cookie.js (https://github.com/js-cookie/js-cookie) , additional code:

function setcookie(cname, cvalue, exdays) {     var d = new date();     d.settime(d.gettime() + (exdays * 24 * 60 * 60 * 1000));     var expires = "expires=" + d.togmtstring();     document.cookie = cname + '=' + cvalue + ';path="/";' + expires; }  function getcookie(cname) {     var name = cname + "=";     var ca = document.cookie.split(';');     ( var = 0; < ca.length; i++) {         var c = ca[i].trim();         if (c.indexof(name) == 0)             return c.substring(name.length, c.length);     }     return ""; }  function checkhistory(targetid) {     var history = getcookie("history");     var htmlcontent = '';      if (history != "") {         var insert = true;         var sp = history.tostring().split(",");         ( var = sp.length - 1; >= 0; i--) {             htmlcontent += '<div id="recentviewes" data-recentviewes="'                     + sp[i] + '"></div> ';             if (sp[i] == document.url) {                 insert = false;             }             document.getelementbyid(targetid).innerhtml = htmlcontent;         }         if (insert) {             sp.push(document.url);         }         setcookie("history", sp.tostring(), 30);     } else {         var stack = new array();         stack.push(document.url);         setcookie("history", stack.tostring(), 30);     } } 

found solution myself:

this code page want have history block:

function checkhistory(targetid) {     var history = getcookie("history");     var htmlcontent = '';      if (history != "") {         var insert = true;         var sp = history.tostring().split(",");         var se = decodeuricomponent(sp).split(",");         ( var = se.length - 1; >= 0; i--) {             htmlcontent += '<div id="recentviewes" data-recentviewes="'                     + se[i] + '"></div> ';             if (se[i] == window.location.pathname) {                 insert = false;             }             document.getelementbyid(targetid).innerhtml = htmlcontent;         }         if (insert) {             se.push(window.location.pathname);         }         setcookie("history", se.tostring(), 30);      } else {         var stack = new array();         stack.push(window.location.pathname);         setcookie("history", stack.tostring(), 30);     } } 

and every folder/page of domain:

function checkhistory(targetid) {     var history = getcookie("history");     var htmlcontent = '';      if (history != "") {         var insert = true;         var sp = history.tostring().split(",");              var se = decodeuricomponent(sp).split(",");          ( var = se.length - 1; >= 0; i--) {             htmlcontent += '<div id="recentviewes" data-recentviewes="'                     + se[i] + '"></div> ';             if (se[i] == window.location.pathname) {                 insert = false;             }             document.getelementbyid(targetid).innerhtml = htmlcontent;         }         if (insert) {             se.push(window.location.pathname);         }  $.cookie('history', se.tostring(), { expires: 30, path: '/' });      } else {         var stack = new array();         stack.push(window.location.pathname);         $.cookie('history', stack.tostring(), { expires: 30, path: '/' });     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -