Reputation: 2106
I'm trying to write a cookie to track visitor recency and I'm hitting a wall with IE8. The error my logs are showing for IE users is the not-so-informative: TypeError: Object doesn't support this property or method.
Any idea what I need to revise in the code below so it works with IE?
var currentDate = Date.now();
var cookies = document.cookie.match(/jcom\=.+\}/);
if (cookies == null) {
var cookieBase = '{"created":"createdNull","lastVisit":"visitNull"}';
var siteTime = $.parseJSON(cookieBase);
siteTime.created = currentDate;
siteTime.lastVisit = currentDate;
cookieOut = "{\"created\":" + siteTime.created + ",\"lastVisit\":" + siteTime.lastVisit + "};expires=Thu, 2 Aug 2020 20:47:11 UTC;path=/";
document.cookie="jcom=" + cookieOut;
}
else {
var cookies = document.cookie.match(/jcom\=.+\}/)[0];
var cookieSplit1 = cookies.split('=')[1];
var cookieSplit= cookieSplit1.split(';')[0]
var siteTime = $.parseJSON(cookieSplit);
siteTime.lastVisit = currentDate;
cookieOut = "{\"created\":" + siteTime.created + ",\"lastVisit\":"+ siteTime.lastVisit + "};expires=Thu, 2 Aug 2020 20:47:11 UTC;path=/";
document.cookie="jcom=" + cookieOut;
}
Thanks!
Upvotes: 0
Views: 2342
Reputation: 324600
Internet Explorer 8 does not support Date.now()
. You can implement it yourself very easily:
if( !Date.now) {
Date.now = function() {return new Date.getTime();};
}
Upvotes: 5