Created
June 24, 2022 18:02
-
-
Save davidsword/eb6577485f9d916246d305b81c4da0ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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