0

I've created a site that, when the homepage index.html loads, it shows an opening animation. Not something spectacular, but repeated seeing of it could become very annoying.

Currently, whenever an user opens index.html he/she sees the animation. That includes typing the URL, navigating from Google or from any internal page.

Is there a way to set so that when a user navigates to the URL manually (or via Google, etc.) the animation (div X) is shown, but when the user navigates from /contact back to /home (index.html) the animation is NOT shown?

This would greatly reduce over and over seeing the animation and improve the experience.

I don't mind if the animation is shown again when the user refreshes the browser. The user should see the animation again everytime he opens a new session; thus after he closed and reopens the website. It should only apply to the current session.

Sander Schaeffer
  • 2,757
  • 7
  • 28
  • 58

1 Answers1

0

Applying the extractDomain() function from this answer to document.referrer (about which you should read more here) and then comparing its result to your domain name should tell you where the user came from.

Then again, this method is far from reliable. Instead I'd recommend creating a cookie when they first visit. By doing that, you can check if your user already has a cookie: if they don't, play the intro and create a cookie, and if they do, don't show it.

If you're wondering about how to implement such a function, read this answer about creating and reading cookies.

Community
  • 1
  • 1
FWDekker
  • 1,823
  • 2
  • 20
  • 26