Rediriger IF cookie n'est pas présent avec minuterie
-
25-10-2019 - |
Question
Je trouve cet extrait:
(function( cn, url ) { if( navigator.cookieEnabled && !new RegExp( "(^|\\s|\\;)" + cn + "=1(\\;|\\s|$)").test( document.cookie ) ) { document.cookie = cn + '=1'; location.assign( url ); } })( "thisSession", "splash.html" );
Source: http://wcdco.info/tF
Comment je pourrais ajouter un délai, laisse dire 1 minute?
La solution
En Javascript il y a la fonction setTimeout () pour cela.
Fenêtre setTimeout () Méthode
Fenêtre objet Définition et utilisation
La méthode setTimeout () appelle une fonction ou évalue une expression après un nombre spécifié de millisecondes.
Conseil:. 1000 ms = 1 seconde
<script>
function doit(cn, url) {
if (navigator.cookieEnabled && !new RegExp("(^|\s|\;)" + cn + "=1(\;|\s|$)").test(document.cookie)) {
document.cookie = cn + '=1'; location.assign(url);
}
}
window.setTimeout(doit("thisSession", "splash.html"), 60 * 1000);
</script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow