I have a pop-up signup box on our site that is supposed to set a cookie when closed to keep it from coming back. Right now it only sets the cookie if the close image is clicked. If you click anywhere else it closes for about ten seconds and then comes back. I don’t see where I need to fix the code. Any suggestions would be appreciated.
<!--- Infusionsoft newsletter signup form start --->
<script type="text/javascript" src="js/jquery.colorbox.js"></script>
<script language="javascript" type="text/javascript">
/*cookie method start here to save and read and delete*/
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 eraseCookie(name) {
createCookie(name,"",-1);
}
/*End here*/
</script>
<script type="text/javascript">
$(document).ready(function(){
/*Check if the device is mobile..*/
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
$('.inline').click(function(e) {
// Check if the mobile device then set width 100%
if(isMobile.any()){
$(".inline").colorbox({inline:true, width:"100%",closeButton:false});
}else{
$(".inline").colorbox({inline:true, width:"50%",closeButton:false});
}
});
$('.inline1').click(function(e) {
// Check if the mobile device then set width 100%
if(isMobile.any()){
$(".inline1").colorbox({inline:true, width:"100%",closeButton:false});
}else{
$(".inline1").colorbox({inline:true, width:"50%",closeButton:false});
}
});
if(readCookie('confirm')!='Yes'){/* If cookie is not set then open other wise no need to open */
setTimeout(function(){$(".inline").trigger("click");},8000);
}
/*Close mthod call here*/
$("##cboxClose1").click(function () {
createCookie('confirm','Yes',10);/*Save variable in cookie for one day*/
parent.$.colorbox.close();
});
$("##cboxClose2").click(function () {
parent.$.colorbox.close();
});
/*These method save data into infusionsoft via ajax*/
$('##submit').on('click', function(e){
var email = $('##email').val();
var bday = $('##month').val()+'-'+$('##year').val();
var name = $('##name').val();
if ( email.length) {
// please change url here
// /fuseaction/home.newsubscriber
$.post('http://www.aquinasandmore.com/actions/act_processnewslettersignup.cfm', $('##foo').serialize(), function(data) {
var data = $.parseJSON(data);
//alert(data);
if (data.status == 'OK') {
window.location.replace('http://www.aquinasandmore.com/fuseaction/service.newsletterthanks');
createCookie('confirm','Yes',1);
parent.$.colorbox.close();
}
else {
alert(data.message);
parent.$.colorbox.close();
}
});
}
else {
$("##error0-response").html("<div style='color:red'>Please enter a valid e-mail address.</div>");
}
});
$('##submit1').on('click', function(e){
var email = $('##email1').val();
var churchname = $('##churchname').val();
var name = $('##name1').val();
if (email.length && churchname.length) {
// please change url here
$.post('http://www.aquinasandmore.com/actions/act_processnewslettersignup.cfm', $('##foo1').serialize(), function(data) {
var data = $.parseJSON(data);
// alert(data);
if (data.status == 'OK') {
alert('Thank you for requesting your guide.');
parent.$.colorbox.close();
}
else {
alert(data.message);
parent.$.colorbox.close();
}
});
}
else {
if(!email.length){
$("##error1-response").html("<div style='color:red'>Please enter a valid e-mail address.</div>");
}
if(!churchname.length){
$("##error2-response").html("<div style='color:red'>Please enter the name of your parish.</div>");
}
}
});
});
</script>
<!-- First Signup Popup which open automatically -->
<p><a class='inline' href="##inline_content" style='display:none;'>Inline HTML</a></p>
<!-- This contains the hidden content for inline calls -->
<div style='display:none'>
<div id='inline_content' style='padding:10px; background:##fff;'>
<form id="foo" action="" method="post">
<h2>Get >FREE SHIPPING< and learn more about the Faith with our newsletter.</h2>
<p>Free shipping coupon included with newsletter.</p>
<p> </p>
<input type='hidden' name='fuseaction' value='newSubscriber'>
<label>Name:</label> <input type='text' name='name' id='name'><br><br>
<label>Birthday (We send coupons!):</label>
<input type='text' name='month' id='month' style='width:25px;' size='2'>/
<input type='text' name='year' id='year' style='width:25px;' size='2'>(mm/dd)<br><br>
<label>Email: </label><span style='color:red;'>*</span><input type='text' name='email' id='email'>
<br><br>
<div id="error0-response"></div>
<br><br>
<input type="button" id="submit" class="button" value="Submit">
<p> </p>
<div id="facebook" style="align:auto;">
<fb:like data-href="https://www.facebook.com/aquinasandmore" width="400" data-send="false" data-show-faces="false" fb-xfbml-state="rendered" class="fb_edge_widget_with_comment fb_iframe_widget"><span style="height: 24px; width: 450px;"><iframe id="fe9caebe4" name="f30ed0e2dc" scrolling="no" title="Like this content on Facebook." class="fb_ltr" src="http://www.facebook.com/plugins/like.php?api_key=298402966940498&channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D27%23cb%3Df35c288f3%26domain%3Dwww.aquinasandmore.com%26origin%3Dhttp%253A%252F%252Fwww.aquinasandmore.com%252Ff1b20af018%26relation%3Dparent.parent&colorscheme=light&extended_social_context=false&href=https%3A%2F%2Fwww.facebook.com%2Faquinasandmore&layout=standard&locale=en_US&node_type=link&sdk=joey&send=false&show_faces=false&width=400" style="border: none; overflow: hidden; height: 24px; width: 400px;"></iframe></span></fb:like>
</div>
<div id="cboxClose1" style="cursor: pointer; position: absolute; top: 0; right: 0;"><!-- <button type="button" id="cboxClose1">close</button> --><img src="images/close.png" alt="close"></div>
</form>
</div>
</div>
<!-- End here signup popup -->