0

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

现在,我遇到的问题是每个会话向旧版本 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]-->
4

2 回答 2

0

使用

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]-->
于 2013-02-10T21:15:02.107 回答
0

如果您只拥有一个 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]-->
于 2013-02-10T21:19:54.217 回答