首页 > 解决方案 > 我只想向 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>

标签: javascriptjquerycookies

解决方案


您可以使用 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);
}

推荐阅读