Javascript – IE8 blocking JavaScript Cookies

blocking, cookies, internet-explorer-8, javascript

Here is one that is throwing me for a loop. I am trying to set a simple cookie that has one name:value pair on IE8. Tested on FF and it works fine. IE8 keeps blocking it.

I have read about the P3P stuff and created a basic P3P doc, no errors reported by the IBM tool, and added the following on all pages:

<meta http-equiv="P3P" CP="CAO DSP COR PSDa CONi TELi OUR STP COM NAV"><link rel="P3Pv1" href="/w3c/p3p.xml"></link>

The code I use to set the cookie is as follows:

function setCompatibilityCookie(c_name, value, expiredays) {var exdate = new Date();exdate.setDate(exdate.getDate() + expiredays);document.cookie= c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toUTCString());}

Any ideas why IE8 keeps blocking me from setting this cookie?

Thank you,

Best Solution

I had the same problem and spent a lot of time digging why IE wont save my JS cookie. My P3P stuff was OK and IE was saving response cookies, but not JS.

Suddenly and most surprisingly I found the solution by removing the following line from html:

< meta http-equiv="Content-Type" content="text/html; charset=utf-8"/ >

I have no idea why that happens but that solved all my problems. Hope this helps someone.