0

In my site i have a welcome animation (created with jquery) which runs when any one opens my website (www.mysite.com). Then the same user going to anther page in my site for example www.mysite.com/about then click back to home (www.mysite.com) the animation again shows up. How can i restrict this ?

Share some logic like putting a session or settimeout or something like that.

Jithesh Kt
  • 2,023
  • 6
  • 32
  • 48

6 Answers6

1

You can set cookie either on server side or either client side And check whether the cookie is set or not if cookie is set then dont show welcome box otherwise show the welcome box...

In php you can set session cookie using setcookie function please see below link:-

http://php.net/manual/en/function.setcookie.php
bipen
  • 36,319
  • 9
  • 49
  • 62
THE ONLY ONE
  • 2,110
  • 1
  • 12
  • 6
1

See the following link for information on how to setup cookies using JQuery: How do I set/unset cookie with jQuery?

Everytime you load the homepage, you can check if the cookie is set using an if-statement. If the cookie is not set, run the animation.

Within the animation-script; make sure that you set the cookie so that the script won't run again while the cookie is active.

Community
  • 1
  • 1
ZeroZipZilch
  • 711
  • 9
  • 27
1

This is how you could do it using jquery cookie plugin:

http://jsfiddle.net/lollero/2nYBV/ ( or http://jsfiddle.net/lollero/2nYBV/show/ )

You might want to change the way cookie expires. That info can be found in the plugin page. The way I did it, it expires after every browser session.

jQuery:

You could just as easily reverse this to hide, if the cookie is set. 1. Set cookie 2. if statement to trigger hide, if cookie is set.

// If "welcome" cookie is not set...
if ( $.cookie('welcome') === null ) {
    // Show welcome text.
    $('#welcome').show();
    // Set the "welcome" cookie, so that the 
    // welcome text will not be shown after this.
    $.cookie('welcome', true );
}
​

CSS:

#welcome { 
    display: none; 
}​

HTML:

<div id="welcome">Welcome</div>​
Joonas
  • 7,227
  • 9
  • 40
  • 65
0

Place timer with flag then redirect to main page in your site.

 setTimeout(function() {window.location.href = "/NewPage.php";}, 2000);
AbuQauod
  • 919
  • 14
  • 30
0

You can use a session to handle this. An example:

<?php
$_SESSION['new'] = true;
?>
Licson
  • 2,231
  • 18
  • 26
0

At first visit main page - define a flag in cookies, and at each visit of page check this flag

iurii_n
  • 1,330
  • 10
  • 17