wcdco
wcdco

Reputation: 3

Redirect IF cookie is not present with timer

I found this snippet:

(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

How I could add a delay, lets say 1 minute?

Upvotes: 0

Views: 198

Answers (1)

dknaack
dknaack

Reputation: 60496

In Javascript there is the setTimeout() function for that.

Window setTimeout() Method

Window Object Definition and Usage

The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

Tip: 1000 ms = 1 second.

<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>

http://www.w3schools.com/jsref/met_win_settimeout.asp

Upvotes: 1

Related Questions