Ciao a tutti,
sto usando "JQuery Modal" (per far apparire un div in sovra-impressione) con abbinati i Cookies solo che lo script che uso io non funziona proprio come vorrei: adesso fin quando non chiudo il browser i cookies funzionano e non mi fanno vedere una seconda volta il div in sovra-impressione ma se chiudo e riavvio il browser si rivede ancora il div in sovra-impressione (solo la prima volta però).
La mia necessità è che questo div non sia mostrato fin quando l'utente non cancella i cookies dal suo browser e quindi non vorrei che invece riappaia semplicemente quando riapre il browser.
Mi aiutate a modificare il mio script ? Non sono molto esperto di Javascript (purtroppo) ...
codice:
setTimeout('ritardo()', 10000);
function ritardo() {
$(document).ready(function() {
//if the cookie hasLaunch is not set, then show the modal window
if (!readCookie('hasLaunch')) {
//launch it
launchWindow('#dialog2');
//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 (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask2').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask2').click(function () {
$(this).hide();
$('.window').hide();
});
$(window).resize(function () {
var box = $('#boxes2 .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
$('#mask2').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.toGMTString();
}
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
$('#mask2').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask2').fadeIn(1000);
$('#mask2').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);
}
}