提问者:小点点

我只想向Internet Explorer(10-11)显示消息,并且每天显示一次


我只想向Internet Explorer(10-11)显示消息,并且每天显示一次

if (navigator.appName == 'Microsoft Internet Explorer' ||  !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1))
{
  $(window).on('load', function () {
    if (!Cookies.get('alreadyShow')) {
    Cookies.set('alreadyShow', true, {
      expires: 1
    });
        $('#ie-note-1').addClass('show');
    }
});
}

由于cookie脚本的原因,消息没有显示,可能IE不工作,或者有什么问题

它总是显示“cookies”是未定义的,但我补充

<script src="http://lab.alexcican.com/set_cookies/cookie.js"></script>

共2个答案

匿名用户

我刚刚在小提琴中检查了您的代码,发现了两个问题:小提琴无法加载cookie脚本,因为正确的URL是https://lab.alexcican.com/set_cookies/cookie.js,而不是http://lab.alexcican.com/set_cookies/cookie.js,并且您错误地使用了该脚本中可用的cookie函数。 根据https://github.com/carhartl/jquery-cookie,更正后的版本为

 $(window).on('load', function() {
    if (!$.cookie('alreadyShow')) {
       $.cookie('alreadyShow', 'true', {
       expires: 1
       });
       $('#ie-note-1').addClass('show');
    }
 });

工作小提琴

匿名用户

您可以使用localStorage来存储变量,并检查它是今天显示还是不显示。

var day = new Date().getDate();
var val = localStorage.getItem("cur_date");
if (!val || val !== day) {
   // Show message and update cur_date
   localStorage.setItem("cur_date", day);
}