Search code examples
http-redirectcookiessplash-screenvisited

Cookie to redirect to splash page


First off, I'd like to say that I'm very new to javascript, jquery and/or php. Of the latter I know nothing and the other two aren't far from that.

That being said, I have been scouring the internet for many hours on too many occasions to count for this (admittedly somewhat specific and yet so widely used) thing. It seems to me as though redirecting people to a splash page with a cookie is as well-kept a secret as the recipe for Coca-Cola.

What I want is rather simple, I thought. When the visitor goes to my website, they arrive at the index.html (as per usual). I want to implement a cookie onto this page that applies itself to the visitor. It must check whether the visitor has been to the site before or not. If not, it redirects to splash.html instead. The splash page will be used for the visitor to select the language in which he/she wishes to view the website with links to other HTML pages - this I can make. I have found some snippets here and there, but the javascript seemed too complicated and to always have something missing, somehow, to be able to apply to me and function properly.

Please help!

To recapitulate:

Visitor loads index.html

Cookie acknowledges

if visited before

Do nothing

else

Redirect to splash.html

Seriously, thank you to anyone who can help me with this.

Also, any help as to where to learn Javascript from absolute scratch easily is appreciated.


Solution

  • I have found out that this solution works for what I need:

    $(function() {
        var COOKIE_NAME = 'splash-page-cookie';
        $go = $.cookie(COOKIE_NAME);
        if ($go == null) {
            $.cookie(COOKIE_NAME, 'test', { path: '/', expires: 183 });
            window.location = "Splash.html"
        }
        else {
        }
    });
    

    This script works with the Carhartl Jquery cookie plugin. Thanks for all the help!