javascript - ie7 cookies not being blocked on my site -
i adding feature website client, showing div on login page if cookies disabled. first started testing within chrome, turned off cookies, , after
if (document.cookies == "") { // show div tell users cookies disabled on machine. }
everything works. in codebehind on page_load attempting set cookie
protected void page_load(object sender, eventargs e) { response.cookies["test"].value = "test"; response.cookies["test"].expires = datetime.now.adddays(1); }
all seems in chrome land. next, go on ie7, block cookies, , safety sake, delete history , cookies in case. expected see div didn't.
so, added else if (document.cookies == "" ) { } read cookie in javascript , sure enough there test cookie.
i went tools -> internnet options -> privacy tab -> , moved slider way top, 'block cookies'. in privacy tab, clicked 'advanced' button , set both first party cookies , third party cookies prompt. i'm thinking should blocked.
for example, test, go google.com in ie7, alerts me if want allow or block 2 cookies google.
is there special need doing check cookies disabled in ie7?
i have created cookies.js file, creating, reading, , deleting
function createcookie(name, value, days) { var expires = ""; if (days) { var date = new date(); date.settime(date.gettime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.togmtstring(); } document.cookie = name + "=" + value + expires + "; path=/"; } function readcookie(name) { // we're going search name of cookie, followed =. create new string , put in nameeq var nameeq = name + "="; // split document.cookie on semicolons. ca becomes array containing cookies set domain , path. var ca = document.cookie.split(';'); (var = 0; < ca.length; i++) { // set c cookie checked. var c = ca[i]; // if first character space, remove using 'substring()' method. continue doing until first character not space. while (c.charat(0) == ' ') c = c.substring(1, c.length); // string c begins name of current cookie. if name of desired cookie, we've found looking for. // need return value of cookie, part of c comes after nameeq. // returning value end function: mission accomplished. if (c.indexof(nameeq) == 0) return c.substring(nameeq.length, c.length); } // if after having gone through cookies, haven't found name looking for, cookie not present, return null. return null; } function erasecookie(name) { createcookie(name, "", -1); } function cookiesenabled() { if (document.cookies == "") { return false; } return true; }
just went ahead , downloaded jquery.cookie.js , in function checking if cookies eanbled, have this:
function cookiesenabled() { var test_cookie = 'test_cookie'; $.cookie(test_cookie, true); if ($.cookie(test_cookie)) { $.cookie(test_cookie, null); return true; } return false; }
this working in chrome , firefox, not in ie7.
i tried this:
function cookiesenabled() { var cookieenabled = (navigator.cookieenabled) ? true : false; if (typeof navigator.cookieenabled === "undefined" && !cookieenabled) { document.cookie = "testcookie"; cookieenabled = (document.cookie.indexof("testcookie") != -1) ? true : false; } return cookieenabled; }
this did work. think @ 1 point or navigator.cookieenabled supported ie, appears chrome , firefox support well.
this thing starting on nerves!!!
here old test found.
does still work ie?
for other browsers needs setcookie, getcookie , delcookie function have if needed
function iscookieenabled() { if (document.all) return navigator.cookieenabled; setcookie('testcookie',today.gettime()); var tc = getcookie('testcookie'); delcookie('testcookie'); return (tc == today.gettime()); } /* cookie functions bill dortsch */ function setcookie (name,value,expires,path,thedomain,secure) { value = escape(value); var thecookie = name + "=" + value + ((expires) ? "; expires=" + expires.togmtstring() : "") + ((path) ? "; path=" + path : "") + ((thedomain) ? "; domain=" + thedomain : "") + ((secure) ? "; secure" : ""); document.cookie = thecookie; } function getcookie(name) { var search = name + "=" if (document.cookie.length > 0) { // if there cookies offset = document.cookie.indexof(search) if (offset != -1) { // if cookie exists offset += search.length // set index of beginning of value end = document.cookie.indexof(";", offset) // set index of end of cookie value if (end == -1) end = document.cookie.length return unescape(document.cookie.substring(offset, end)) } } } function delcookie(name,path,domain) { if (getcookie(name)) document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=thu, 01-jan-70 00:00:01 gmt"; // alert(name+' marked deletion'); }
Comments
Post a Comment