How to remove cookies after 5 minutes after clicking the button?

$('#click').on('click', 'submit', function(){
 document.cookie = "userSubmitClick=1; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT";
 let setCookie = unescape((RegExp('userSubmitClick=([^;]+)').exec(document.cookie) || [1, "])[1]);
 if (setCookie) {
 /*Start the timer, and then derive аlert*/
}
});
April 4th 20 at 13:01
2 answers
April 4th 20 at 13:03
Solution
$('#click').on('click', 'submit', function() {
 // 5 min == 300sec
 document.cookie = 'userSubmitClick=1; path=/; max-age=300';
});

and yet, the browser will remove the cookie itself, even if the tab is closed
and no need to reinvent the wheel
Click-through 16.33 20.01.2020 gives the cookies the following: 2020-01-20T14:33:30.134 Z - Jammie_McKenzie commented on April 4th 20 at 13:06
@the_killer_ducks, and what is your timezone in the system? - janae97 commented on April 4th 20 at 13:09
@v3shinright... hours and not minutes considered)) I corrected the answer - janae97 commented on April 4th 20 at 13:12
@brady.Lemke82, UTC+3 - Jammie_McKenzie commented on April 4th 20 at 13:15
@brady.Lemke82, This is called a "set cookie life time". Standard technology from ancient times. - arden.Torphy commented on April 4th 20 at 13:18
April 4th 20 at 13:05
$('#click').on('click', 'submit', function(){
 document.cookie = "userSubmitClick=1; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT";
 let setCookie = unescape((RegExp('userSubmitClick=([^;]+)').exec(document.cookie) || [1, "])[1]); // replace unescape decodeURI on
 if (setCookie) {
 /*Start the timer, and then derive аlert*/
 // The function for deleting all cookies https://stackoverflow.com/a/179514
 setTimeout(() => deleteAllCookies(), 5 * 60 * 1000);
}
});
This will only work if the user is on the website at the time of expiry of the timer - shannon_Bernier commented on April 4th 20 at 13:08
@estell_Kub, apparently did not understand the question on the title. And so the option @brady.Lemke82 the "normal" - harmon56 commented on April 4th 20 at 13:11

Find more questions by tags JavaScript