You can put a cookie on the browser of the user and check on the load of the page if the cookie exist like on the code below.
When you click the x or on the 'I agree!' link, the message will not show again.
You can reload the page it don't show again.
You have to delete the cookie to see the message again, so i added a button to delete the cookie and reload the page. If you click on "Click for delete cookie", the cookie disapear and message apear.
<!DOCTYPE html>
<head>
<title>Stack Overflow</title>
<body onload="checkBtn()">
<div id="cookieConsent" style="display:none">
<div id="closeCookieConsent" onClick=javascript:addBtn();>x</div>
This website is using cookies. <a href="files/c11bg_cookie_policy.pdf" target="_blank">More info</a>. <a href="#" onClick=javascript:addBtn(); class="cookieConsentOK">I agree!</a>
</div>
<br/>
<br/>
<br/>
<br/>
<div id=btnHolder ><input type="button" onClick=javascript:delCookie("btn"); value="Click for delete cookie" /></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
/*$(document).ready(function(){
setTimeout(function () {
$("#cookieConsent").fadeIn(200);
}, 4000);
$("#closeCookieConsent, .cookieConsentOK").click(function() {
$("#cookieConsent").fadeOut(200);
});*/
function addBtn(){
if(getCookie("btn"))
document.getElementById('cookieConsent').style.display = 'none';
document.getElementById('cookieConsent').style.display = 'none';
setCookie("btn",true,5);
}
function checkBtn(){
if(!getCookie("btn"))
document.getElementById('cookieConsent').style.display = '';
}
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname){
return (document.cookie.match('(^|; )'+ cname +'=([^;]*)')||0)[2]
}
function delCookie(cname) {
document.cookie = cname+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
window.location.reload();
}
</script>
</body>
I comment the jquery part because it gave me an error.