créer un cookie basé sur une session, jquery

Le code suivant affiche un message contextuel lors du chargement de la page et crée un cookie de sorte que, lorsque l’utilisateur revient à la page, il ne voit plus le message contextuel. la durée de vie du cookie est basée sur le temps. J’aimerais modifier ce code afin que la durée de vie du cookie soit basée sur la session de l’utilisateur ou sur un jour. des conseils ou des extraits de code seraient formidables. Merci.

lien vers la démonstration du code: http://www.queness.com/post/77/simple-jquery-modal-window-tutorial

    $(document).ready(function() { //if the cookie hasLaunch is not set, then show the modal window if (!readCookie('hasLaunch')) { //launch it launchWindow('#dialog'); //then set the cookie, so next time the modal won't be displaying again. createCookie('hasLaunch', 1, 365); } //if close button is clicked $('.window #close').click(function () { $('#mask').hide(); $('.window').hide(); }); //if mask is clicked $('#mask').click(function () { $(this).hide(); $('.window').hide(); }); $(window).resize(function () { var box = $('#boxes .window'); //Get the screen height and width var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Set height and width to mask to fill up the whole screen $('#mask').css({'width':maskWidth,'height':maskHeight}); //Get the window height and width var winH = $(window).height(); var winW = $(window).width(); //Set the popup window to center box.css('top', winH/2 - box.height()/2); box.css('left', winW/2 - box.width()/2); }); }); function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTSsortingng(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function launchWindow(id) { //Get the screen height and width var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Set heigth and width to mask to fill up the whole screen $('#mask').css({'width':maskWidth,'height':maskHeight}); //transition effect $('#mask').fadeIn(1000); $('#mask').fadeTo("slow",0.8); //Get the window height and width var winH = $(window).height(); var winW = $(window).width(); //Set the popup window to center $(id).css('top', winH/2-$(id).height()); $(id).css('left', winW/2-$(id).width()/2); //transition effect $(id).fadeIn(2000); }   body { FONT-FAMILY: verdana; FONT-SIZE: 15px } A { COLOR: #333; TEXT-DECORATION: none } A:hover { COLOR: #ccc; TEXT-DECORATION: none } #mask { Z-INDEX: 9000; POSITION: absolute; BACKGROUND-COLOR: #000; DISPLAY: none; TOP: 0px; LEFT: 0px } #boxes .window { Z-INDEX: 9999; POSITION: fixed; PADDING-BOTTOM: 20px; PADDING-LEFT: 20px; WIDTH: 640px; PADDING-RIGHT: 20px; DISPLAY: none; HEIGHT: 385px; PADDING-TOP: 20px } #boxes #dialog { PADDING-BOTTOM: 10px; BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 10px; WIDTH: 640px; PADDING-RIGHT: 10px; HEIGHT: 385px; PADDING-TOP: 10px } .redbox { color: #F00; font-weight: bold; } .bold { font-weight: bold; }  
pop up message Ok

Un cookie de session est un cookie sans heure d’expiration, changez donc ceci:

 createCookie('hasLaunch', 1, 365); 

à:

 createCookie('hasLaunch', 1); 

mieux utiliser la fonction de stockage de session HTML5, car les cookies peuvent être désactivés par certains utilisateurs.

vous pouvez essayer comme ça.

 var isFirst = sessionStorage.getItem("FIRSTVISIT"); if(isFirst == null || isFirst == 'undefined') { sessionStorage.setItem("FIRSTVISIT", "YES"); launchWindow('#dialog'); }