Skip to content

Instantly share code, notes, and snippets.

@davidsword
Created June 24, 2022 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsword/eb6577485f9d916246d305b81c4da0ea to your computer and use it in GitHub Desktop.
Save davidsword/eb6577485f9d916246d305b81c4da0ea to your computer and use it in GitHub Desktop.
<body onload="showOrHideAlert()">
<div id='alert' style="background:yellow">
Alert banner generated by PHP, always in the HTML
<a id='alert_dismiss' onclick="setDismissAlertCookie()">[X]</a>
</div>
<script>
function showOrHideAlert() {
const hidden = document.cookie.split('; ').find(row => row.startsWith('dismissAlert='))?.split('=')[1];
if ( '1' == hidden )
document.querySelector('#alert').hidden=true;
}
function setDismissAlertCookie() {
document.cookie = "dismissAlert=1";
document.querySelector('#alert').hidden=true;
}
</script>
hello world.
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment