0

調べてみたところ、正確な解決策を見つけることができませんでしたが、存在する場合はお詫び申し上げます。

現在、私が抱えている問題は、Internet Explorer の古いバージョン、つまり IE9 未満のユーザーに対して、セッションごとに 1 回 div を表示することです。

これが私がすぐにまとめたコードですが、機能していないようです。誰かが何が問題なのか教えてもらえますか? 私はそれをすべて間違っていますか?

<!--[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

その 1 つの 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 に答える