hyteck-blog/layouts/shortcodes/cookie_button.html

25 lines
676 B
HTML

<!---
Adds a button that, when you click it stores a cookie for the user.
Use as [curly_brace x 2]< cookie_button cookie_key cookie_value button_text>[closing_curly_brace x 2]
-->
<script>
function createCookie(name, value, days){
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
else {
expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/; samesite=strict;";
}
</script>
<button onclick="createCookie('{{ index .Params 0}}', '{{ index .Params 1}}', 365)">{{ index .Params 2}}</button>