cookies - Run javascript function once a week -
i have below javascript function runs on every visit. not want spam our visitors popup on every visit trying head around cookies , running once week.
settimeout(function() { jquery(document).one('mouseleave', function() { console.log('mouse left'); jquery('.open-popup-link').magnificpopup('open'); }); }, 10000);
i placed within cookie function found on here nothing runs , no errors in console.
function setcookie(cname, cvalue, exdays) { var d = new date(); d.settime(d.gettime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toutcstring(); document.cookie = cname + "=" + cvalue + "; " + expires; } function getcookie(cname) { var name = cname + "="; 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); if (c.indexof(name) != -1) return c.substring(name.length,c.length); } return ""; } function checkcookie() { var pinball = getcookie("pinball"); if (pinball === "") { // cookie not set settimeout(function() { jquery(document).one('mouseleave', function() { console.log('mouse left'); jquery('.open-popup-link').magnificpopup('open'); }); }, 10000); setcookie("pinball", "seen", 7); } }
what have missed or need make run?
i agree @mysterx local storage, answer question - reading code - there not seem call trigger checkcookie() means there no errors because function has not run.
you should have:
$(document).ready(function(){ checkcookie() })
also have typo in first section of code , in checkcookie function - same error - have :
jquery(document).one('mouseleave', function() {...
and should .
jquery(document).on('mouseleave', function() {...
Comments
Post a Comment