每个会话向IE6-8用户显示一次警告



我环顾四周,找不到确切的解决方案,但如果确实存在,我深表歉意。

现在,我遇到的问题是向旧版本的Internet Explorer的用户显示一个div,即<IE9.

这是我很快整理好的代码,但它似乎不起作用,有人能告诉我它出了什么问题吗?我做错了吗?

<!--[if lt IE 9]>
<script>
    /* Set initial cookie after entire page has loaded */
    document.cookie="messageseen=true";
    /*********** 
       This cookie won't exist initially, but when the if statement below checks
       for the message seen cookie, the clear message cookie will also be set,
       this is so on subsequent page-loads, it won't take 5 seconds for the the
       message to disappear. 
    ***********/
    if (document.cookie == "clearmessage") {
       $('.ie-message').hide(); // hide message without delate
    }
    /*********** 
       After 5 seconds, check for the messageseen cookie, if it exists, set the
       clearmessage cookie and hide .ie-message. On all subsequent page-loads,
       the message will be hidden immediately without the delay.
    ***********/
    setTimeout(function (){
       if (document.cookie == "messageseen") {
          document.cookie="clearmessage=true";
          $('.ie-message').hide(); // hide message if cookie is set
       }
    }, 5000); // delay the hiding of the message for 5 seconds
</script>
<![endif]-->

使用

https://github.com/carhartl/jquery-cookie

<!--[if lt IE 9]>
<script>
    /* Set initial cookie after entire page has loaded */
    $.cookie("messageseen",true);
    /*********** 
       This cookie won't exist initially, but when the if statement below checks
       for the message seen cookie, the clear message cookie will also be set,
       this is so on subsequent page-loads, it won't take 5 seconds for the the
       message to disappear. 
    ***********/
    $('.ie-message').toggle(!$.cookie("clearmessage")); // hide message without delate
    /*********** 
       After 5 seconds, check for the messageseen cookie, if it exists, set the
       clearmessage cookie and hide .ie-message. On all subsequent page-loads,
       the message will be hidden immediately without the delay.
    ***********/
    setTimeout(function (){
       if ($.cookie("messageseen")) {
          $.cookie("clearmessage",true);
          $('.ie-message').toggle(0); // hide message if cookie is set
       }
    }, 5000); // delay the hiding of the message for 5 seconds
</script>
<![endif]-->

如果你只想要一个cookie,你可以这样做:(注意,我将div隐藏在内联中,以防止在页面加载缓慢时闪烁)

<!--[if lt IE 9]>
<div class"ie-message" style="display:none;">IE MESSAGE</div>
<script>
(function($){
  if ( document.cookie == "" ) {
  // show message
  $('.ie-message').show();
  // add cookie;
  document.cookie = "seen=true";
}
</script>
<![endif]-->

最新更新