I'm confused again - sorry! I think (?!) I need a cookie that expires when the user closes the browser - is that called a session cookie? So that when someone opens the website they have to click the "Accept" button to see the website but when they leave the site and revisit, they have to click accept again. Or, failing that, could I place a 1 hour expiration code on the cookie - would this line need altering? [ $.cookie('no_thanks', 'true', { expires: 36500, path: '/' });] Sorry to be a pain but any help on this would be brilliant.
The cookie is set to expire in 1 minute..............(see code below)......... alter to how many minutes/hours/days you think you need.
Only thing with cookies is you are meant to give a warning message to your users that you are putting something on their computer.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Modal</title>
<!-- Bootstrap Core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Latest jQuery Library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Bootstrap Core JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<!-- Cookie JS for Modal -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.min.js"></script>
<style>
.modal-footer {
display: flex;
justify-content: center;
}
.modal-dialog {
margin: 0 auto;
padding: 0;
position: relative;
top: 40%;
transform: translateY(-40%);
}
</style>
</head>
<body>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<p class="text-center">We are committed to safeguarding and promoting the welfare of children and young people. To view our website we ask you to accept our policies. For more information please click on the button below.</p>
<p class="text-center"><a href="safeguarding_gdpr_acceptance.html" target="_blank"><button type="button" class="btn btn-primary">View our policies</button></a></p>
</div>
<div class="modal-footer">
<!-- Make sure to include the 'nothanks' class on the buttons -->
<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">I Don't Accept</button>
<button class="btn btn-default decline" data-dismiss="modal" aria-hidden="true">I Accept</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
// Delayed Modal Display + Cookie On Click
$(document).ready(function() {
// If no cookie with our chosen name (e.g. decline)...
if ($.cookie("decline") == null) {
// Show the modal, with delay func.
$('#myModal').appendTo("body");
function show_modal(){
$('#myModal').modal();
}
// Set delay func. time in milliseconds
window.setTimeout(show_modal, 500);
}
// On click of specified class (e.g. 'decline'), trigger cookie, which expires in 100 years
$(".decline").click(function() {
var date = new Date();
var minutes = 1;
date.setTime(date.getTime() + (minutes * 60 * 1000));
$.cookie("decline", "true", { expires: date, path: '/' });
});
});
</script>
</body>
</html>