Fix cookie button.
The button is now implemented via a neat shortcode
This commit is contained in:
24
layouts/shortcodes/cookie_button.html
Normal file
24
layouts/shortcodes/cookie_button.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<!---
|
||||
|
||||
Adds a button that, when you click it stores a cookie for the user.
|
||||
|
||||
Use as {{< cookie_button cookie_key cookie_value button_text>}}
|
||||
-->
|
||||
<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>
|
||||
|
||||
|
Reference in New Issue
Block a user