0

我正在尝试编写一个 cookie 来跟踪访问者的新近度,而我正在使用 IE8 碰壁。我的日志向 IE 用户显示的错误信息不那么丰富:TypeError: Object does not support this property or method。

知道我需要在下面的代码中修改什么以便它与 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;
}

谢谢!

4

1 回答 1

5

Internet Explorer 8 不支持Date.now()。你可以很容易地自己实现它:

if( !Date.now) {
    Date.now = function() {return new Date.getTime();};
}
于 2012-10-09T22:02:10.237 回答