Clear cookies with javascript -
i ask here. have update form , when submit need send 2 values main page. (they contains combobox index , table rowindex trigger them , show me selected item have choose before submit. otherwise selects first items) im using cookies , works well. problem cant clear cookies. after update loads previous values when document load.
i have following:
document.cookie="data1="+variable1+"; path=/"; document.cookie="data2="+variable2+"; path=/"; //they holds variables//
and when page loads data back:
$(document).ready(function() { var x = document.cookie.split(';'); if ( x !== null) { var x1 = x[0].split('=')[1]; var x2 = x[1].split('=')[1]; }; //i need cookie clear function here next time page loads select first items again//
i tried none of them works:
1st:
function clearlistcookies(){ var cookies = document.cookie.split(";"); (var = 0; < cookies.length; i++){ var clear = cookies[i].split("="); document.cookie = clear[0] + "=;expires=thu, 21 sep 1979 00:00:01 utc;"; } }
2nd:
document.cookie = "data1=; expires=thu, 01 jan 1970 00:00:00 utc"; document.cookie = "data2=; expires=thu, 01 jan 1970 00:00:00 utc";
thanks in advance
you need specify path
so:
document.cookie = "data1=; expires=thu, 01 jan 1970 00:00:00 utc; path=/"; document.cookie = "data2=; expires=thu, 01 jan 1970 00:00:00 utc; path=/";
Comments
Post a Comment