Удаление cookies
HTML
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<p>hello!</p>
<div class="popup">
popup text
<span class="close">close popup</span>
</div>
CSS
.popup {
display: none;
width: 400px;
height: 300px;
padding: 20px;
border: 3px dashed yellowgreen;
text-align: center;
}
.show-popup .popup {
display: block;
}
.close {
display: block;
width: 200px;
height: 40px;
margin: 100px auto 0 auto;
text-align: center;
line-height: 40px;
background: #dddddd;
cursor: pointer;
}
JavaScript
function checkPopup() {
if ( getCookie('popup') == 'shown' ) {
return false;
} else {
showPopup();
document.cookie = "popup=shown; path=/; expires=0";
}
}
function showPopup() {
$('body').addClass('show-popup');
}
function closePopup() {
$('.close').click(function() {
$('body').removeClass('show-popup');
});
}
function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
$(document).ready(function(){
checkPopup();
//showPopup();
closePopup();
});