javascript - JS cookie drop and countdown timer not working -
hi can have @ below , tell me why not working?
i trying create popup box countdown timer , set cookie doesn't popup box on every page. it's supposed set cookie , detect , think it's doing count down timer isn't visibly counting down.
$(document).ready(function() { if(readcookie('oldsite') != 'stay') //unless find cookie, show banner ... { var time_left = 12; var cinterval; cinterval = setinterval('time_dec()', 1000); var id = '#dialog'; //get screen height , width var maskheight = $(document).height(); var maskwidth = $(window).width(); //set heigth , width mask fill whole screen $('#mask').css({'width':maskwidth,'height':maskheight}); //transition effect $('#mask').fadein(500); $('#mask').fadeto("slow",0.9); //get window height , width var winh = $(window).height(); var winw = $(window).width(); //set popup window center $(id).css('top', winh/2-$(id).height()/2); $(id).css('left', winw/2-$(id).width()/2); //transition effect $(id).fadein(2000); //if disagree word clicked $('#disagree').click(function () { $(this).hide(); $('.window').hide(); $('#mask').hide(); time_left = 0; }); //if mask clicked $('#mask').click(function () { createcookie('oldsite', 'stay', 1); //create cookie 1 day $(this).hide(); $('.window').hide(); }); } //functions function time_dec(){ time_left--; document.getelementbyid('countdown').innerhtml = time_left; if(time_left == 1){ var originalstring = document.getelementbyid('countdown2').innerhtml; var newstring = originalstring.replace('seconds','second'); document.getelementbyid('countdown2').innerhtml = newstring; window.location.replace("http://cadfemukandireland.com/"); clearinterval(cinterval); } } function createcookie(name, value, days) { var expires; if (days) { var date = new date(); date.settime(date.gettime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.togmtstring(); } else { expires = ""; } document.cookie = encodeuricomponent(name) + "=" + encodeuricomponent(value) + expires + "; path=/"; } function readcookie(name) { var nameeq = encodeuricomponent(name) + "="; var ca = document.cookie.split(';'); (var = 0; < ca.length; i++) { var c = ca[i]; while (c.charat(0) === ' ') c = c.substring(1, c.length); if (c.indexof(nameeq) === 0) return decodeuricomponent(c.substring(nameeq.length, c.length)); } return null; } function erasecookie(name) { createcookie(name, "", -1); } });
the css is:
/* css document */ #mask { position: absolute; left: 0; top: 0; z-index: 9000; background-color: #000; display: none; } #boxes .window { position: absolute; left: 0; top: 0; width: 440px; height: 200px; display: none; z-index: 9999; padding: 20px; border-radius: 15px; text-align: center; } #boxes #dialog { width: 750px; height: 300px; padding: 75px 50px 10px 50px; background-color: #ffffff; font-family: 'segoe ui light', sans-serif; font-size: 15pt; } #popupfoot { font-size: 16pt; position: absolute; bottom: 0px; width: 350px; left: 225px; padding-bottom:20px; } #disagree { cursor:pointer; }
and html is:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="boxes"> <div id="dialog" class="window"> <p>as part of our re branding cadfem, have new website</p> <p>you redirected new website <span id="countdown2">in <span id="countdown">12</span> seconds</span>.</p> <div id="popupfoot" style="padding-bottom:100px;"> if wish stay on old website, please click <a id="disagree"><b><u>here</u></b></a> </div> </div> <div id="mask"></div>
you can use creative tools
<div id="timer"></div> <script> $(document).ready(function(){ $("#timer").countdown({ duration : 30, // discount start defined number (in case 30 seconds) default: 0 interval : 1000, // interval in millisecond (default: interval every 1000ms (1 second)) text_before : "redirection begins in ", // initial text before number (example: redirection begins in 30), default: blank text_after : "seconds" // initial text after number (example: 30seconds), default: blank }, // callback function when discount stop on 0 function(){ this.html("done counting, redirecting."); window.location = "http://www.google.com"; }); }); </script>
also cookie function:
// set session cookie $.cookie('the_cookie', 'the_value'); $.cookie('the_cookie'); // -> 'the_value' // set cookie expires in 7 days $.cookie('the_cookie', 'the_value', { expires: 7 }); // delete cookie $.cookie('the_cookie', null);
you can copy 2 functions , integrate code or use whole creative tools.
also can use local storage function if storage disabled or not exist use cookie:
// set session storage $.storage('the_name', 'the_value'); // session storage $.storage('the_name'); // delete storage $.storage('the_name', null);
Comments
Post a Comment