0
I built the following code so that it would preserve a cookie from opening and closing the modal, so that it would not be displayed in a 24-hour period, but it does not work for some reason that I do not know, by logic the code seems to be correct. follows the codes.
$(document).ready(function() {
// If para mostrar ou ocultar a mensagem
if (!readCookie('hide')) {
$('#modal').show();
}
// Adiciona o evento "fechar"
// Assim não exibe novamente
$('#botao').click(function() {
$('#modal').hide();
createCookie('hide', true, 1)
return false;
});
});
// ---
// Lócica do cookie
// ---
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);
}
.success {
color: white;
text-align: center;
}
.error {
color: white;
text-align: center;
}
.modalfox {
font-family: "forzabook", Arial, Helvetica, sans-serif;
background-image: url(/arquivos/modal-fox-brasil.png);
position: fixed;
text-align: center;
line-height: 1.42;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
-webkit-box-sizing: border-box;
background-position: center center;
box-sizing: border-box;
background-repeat: no-repeat;
width: 350px;
-moz-box-sizing: border-box;
height: 550px;
position: fixed;
transition: opacity 0.15s linear;
z-index: 100001;
top: 2%;
left: 40%;
height: 600px
}
.reModalMask .newsletter {
font-family: "forzabook", Arial, Helvetica, sans-serif;
margin-top: 440px;
}
input.newsletter-client-email {
border-radius: 3px;
font-family: "forzabook", Arial, Helvetica, sans-serif!important;
-webkit-box-sizing: border-box;
width: 250px;
font-size: 14px;
-moz-box-sizing: border-box;
box-sizing: border-box;
height: 30px;
}
input.newsletter-client-name {
border-radius: 3px;
-webkit-box-sizing: border-box;
width: 250px;
font-size: 14px;
font-family: "forzabook", Arial, Helvetica, sans-serif;
-moz-box-sizing: border-box;
box-sizing: border-box;
height: 30px;
}
.newsletter p {
display: none!important;
}
.newsletter h3 {
display: none!important;
}
.reModalMask {
height: 100%;
width: 100%;
top: 0;
right: 0;
position: fixed;
background-color: rgba(0, 0, 0, 0.45);
font-family: sans-serif;
z-index: 999999;
}
#botao {
color: white;
background-color: red;
border: none;
float: right;
border-radius: 3px;
width: 20px;
height: 20px;
font-weight: bold;
}
#botao:hover {
background-color: black;
border: solid black 1px;
border-radius: 3px;
}
@media screen and (min-width: 240px) and (max-width: 600px) {
.reModalMask {
display: none!important;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<div class="reModalMask" id="reModalMask">
<div class="col-md-12 modalfox" id="modal">
<a href="JavaScript:void(0)" title="Não quero receber promoções da FOX!" id="botao">X</a>
<vtex.cmc:newsletterOptIn />
</div>
</div>
Would anyone have a light ? I thank you in advance!
This is it ' Document.cookie = name+"="+value+expires+"; path=/"; ' should not be in this pattern Document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
– Matheus
I didn’t understand this pattern you mentioned, could you be more specific ? Thank you for the answer...
– Julio Santos
http://www.w3schools.com/js/js_cookies.asp
– Matheus
He sets a standard there Mm beauty I’ll try thank you!
– Julio Santos
Try removing the "!" from the first "if"".
– MagicHat