Partage
  • Partager sur Facebook
  • Partager sur Twitter

Create cookies for each page

    30 août 2017 à 11:28:41

    Hi friends , i'm using intro.js to help users to understand my website parts . Now i need to add intro js to many page. If i try to use it in another , i can't see tuto because cookies isn't empty ! . This a part of my code and thanks for help . 

    function setCookie(c_name,value,exdays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays===null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
    }
    //check for the cookie when user first arrives, if cookie doesn't exist call the intro.
    function getCookie(c_name)
    {
    var c_value = document.cookie;
    var c_start = c_value.indexOf(" " + c_name + "=");
    if (c_start === -1)
      {
      c_start = c_value.indexOf(c_name + "=");
      }
    if (c_start === -1)
      {
      c_value = null;
      }
    else
      {
      c_start = c_value.indexOf("=", c_start) + 1;
      var c_end = c_value.indexOf(";", c_start);
      if (c_end === -1)
      {
    c_end = c_value.length;
    }
    c_value = unescape(c_value.substring(c_start,c_end));
    }
    return c_value;
    }
    </script>
    <head>
    <script type="text/javascript">
    function checkCookieIntro(){
       var cookie=getCookie("mySite");
    
       if (cookie==null || cookie=="") {
          setCookie("mySite", "1",90);
          runIntro();  //change this to whatever function you need to call to run the intro
          }
    }
    
    </script>
    </head>




    • Partager sur Facebook
    • Partager sur Twitter
    Anonyme
      30 août 2017 à 13:54:34

      Instead of creating a cookie that says "Hey the tutorial has been seen!" right when the page loads, shouldn't you create it when the tutorial is actually completed?

      By "completed", I mean either the user has reached the last step or one has clicked the "skip" button.


      PS: Please be intransigent with my English mistakes if you find some.

      -
      Edité par Anonyme 30 août 2017 à 13:55:55

      • Partager sur Facebook
      • Partager sur Twitter
        30 août 2017 à 14:00:27

        Hello, I move in the forum in English
        • Partager sur Facebook
        • Partager sur Twitter

        Create cookies for each page

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown