Fix cookie button.
The button is now implemented via a neat shortcode
This commit is contained in:
parent
bed96fc7ed
commit
65fbb83fe6
@ -3,7 +3,7 @@ title: "Why Hyteck"
|
|||||||
date: 2019-09-16T18:18:10+02:00
|
date: 2019-09-16T18:18:10+02:00
|
||||||
draft: false
|
draft: false
|
||||||
image: ""
|
image: ""
|
||||||
categrories: [English]
|
categories: ['English', 'me']
|
||||||
tags: ['about']
|
tags: ['about']
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -29,23 +29,7 @@ pronounciation is a Homophone of Tech.
|
|||||||
|
|
||||||
The Hy stayed as I always had a close connection to water.
|
The Hy stayed as I always had a close connection to water.
|
||||||
|
|
||||||
|
|
||||||
I feel like I overexplained this a bit, so poor you if you read till the end.
|
I feel like I overexplained this a bit, so poor you if you read till the end.
|
||||||
|
|
||||||
<script>
|
However, you earned a {{< cookie_button achievement TLDR_restistant cookie>}}!
|
||||||
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>
|
|
||||||
|
|
||||||
Have a <button onclick="createCookie('achievement', 'TLDR_resistant', 365)">cookie</button>
|
|
||||||
|
|
||||||
|
|
||||||
|
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>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user