-2

i'm working on a site currently that has a 15 second intro on the index.html - with a skip button (that leads to main.html) - and was wondering if it is possible to use a cookie to store info on user and thereby directing them straight to the main page on their second visit to the site?

i've been doing webstuff for years but never had the need to use a cookie.

anyone?

Emma.G
  • 3
  • 2
  • 2
    Possible duplicate of [Check if user has alread visited site in browser session](http://stackoverflow.com/questions/28533409/check-if-user-has-alread-visited-site-in-browser-session) – Chief Wiggum Mar 16 '16 at 22:15
  • 1
    `i've been doing webstuff for years but never had the need to use a cookie.` you don't say – Michał Perłakowski Mar 16 '16 at 22:24
  • oh, great, thank you so much for such a creative and positive message, thank you dearly. :| – Emma.G Mar 16 '16 at 23:07

2 Answers2

0

Yes, it is possible using javascript.

js

if(document.cookie) {
    window.location = "http://www.google.com";
} else {
    document.cookie = "visted=yes";
}

But please, rethink the idea of a forced intro keeping a visitor from your site. Anything that stops a person from getting to the content they're looking for will more than likely result in them backing out and not returning.

Fhtagn
  • 753
  • 5
  • 9
  • yeah, that has crossed my mind. this is why the clear "skip" link is in place. the site itself if is supposed to be cinematic,.... otherwise i'd never do it., i hate waiting just as much as everyone. – Emma.G Mar 16 '16 at 23:13
0

In this thread is how to create and read cookies How do I create and read a value from cookie?

In this link is example for redirect https://www.perlscriptsjavascripts.com/js/cookie_redirect.html

 // page to go to if cookie exists
 go_to = "http://www.perlscriptsjavascripts.com";

function readCookie(cookieName){
    var start = document.cookie.indexOf(cookieName);
    if (start == -1){ 
        document.cookie = "seenit=yes; expires=" + ged(num_days);
    } else {
        window.location = go_to;
    }
}


readCookie("seenit");
Community
  • 1
  • 1
ralf htp
  • 9,149
  • 4
  • 22
  • 34