# Show an HTML element once per visit

**URL:** <https://forum.getkirby.com/t/show-an-html-element-once-per-visit/21847>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 8, 2021, 8:10am UTC](https://forum.getkirby.com/t/show-an-html-element-once-per-visit/21847 "2021-04-08T08:10:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexpi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/alexpi/32/12008_2.png) [@alexpi](https://forum.getkirby.com/u/alexpi)\
**Post date:** [April 8, 2021, 8:10am UTC](https://forum.getkirby.com/t/show-an-html-element-once-per-visit/21847/1 "2021-04-08T08:10:02Z")

</div>

I have a small animation on the home page of a site. I want to show it during the first time the user visits the home page (not everytime they visit it again while browsing). If they close the window/tab, it should appear again on the next visit. Hope it makes sense!

I tried Kirby’s session, but I can’t find a way to make the duration last for a single site visit. I also tried the browser’s sessionStorage, but since JS must be executed, reading from it introduces a small delay from hiding the animation to showing the page.

Any ideas how to approach this?

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [April 8, 2021, 5:04pm UTC](https://forum.getkirby.com/t/show-an-html-element-once-per-visit/21847/2 "2021-04-08T17:04:34Z")

</div>

You could probably drop a simple cookie when they visit and then unset it when they leave. You might find these useful:

> **[Setting and reading cookies with JavaScript](https://clubmate.fi/setting-and-reading-cookies-with-javascript)**
>
> Here's two different methods to read and write cookies using JavaScript and/or jQuery. Pure JavaScript Here’s a set of functions: Source It…

> **[How to detect browser or tab closing in JavaScript ? - GeeksforGeeks](https://www.geeksforgeeks.org/how-to-detect-browser-or-tab-closing-in-javascript/)**
>
> A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

---

<div class="post-metadata">

**Author:** ![alexpi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/alexpi/32/12008_2.png) [@alexpi](https://forum.getkirby.com/u/alexpi)\
**Post date:** [April 9, 2021, 7:56am UTC](https://forum.getkirby.com/t/show-an-html-element-once-per-visit/21847/3 "2021-04-09T07:56:37Z")

</div>

I tried the cookie solution, but a proper way to detect window/tab closing doesn’t seem to exist. `unload/beforeunload` events happen on every page load, not for a site visiting session.

I think I will have the animation as a separate page and transition it to the main one.
