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, Schalk
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.
One problem may be that you're using getDate()
, which returns the day of the month. If your expiredays
is too great, it should roll over to next month, but in IE it may be staying in this month and expiring right away. Maybe try this:
function setCompatibilityCookie(c_name, value, expiredays) {
var exdate = new Date();
exdate.setTime(exdate.getTime() + (expiredays * 86400000));
document.cookie= c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toUTCString());}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With