1

I am very, very new at this. What function and where do I place this function in the code below that will only run once per visit?

<script>
jQuery('.count').each (function () {
    jQuery(this).prop('Counter',0).animate({
        Counter: jQuery(this).text()
    }, {
        duration: 4000,
        easing: 'swing',
        step: function (now) {
            jQuery(this).text(Math.ceil(now));
        }
    });
});
</script>

2 Answers2

1

Updated the answer. You can try to use session storage.

  if (!sessionStorage.firstVisit) {
        console.log('first time');
        //run your desired code here.

       sessionStorage.setItem("firstVisit", "1");
    }
Krishnadas PC
  • 5,981
  • 2
  • 53
  • 54
  • 2
    Probably should be session storage, otherwise it will be once forever. – Barmar Feb 15 '18 at 01:00
  • @Barmar Thank you for mentioning. Am currently from a mobile device. So couldn't run this code. If there are any other corrections please make it. – Krishnadas PC Feb 15 '18 at 01:16
0

Took from here: #a/1599367/6687923

Include JQuery.Сookie Library (after include JQuery library):

<head>
// ...
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
// ... 
</head>

Use this script:

<script>
if(!$.cookie("firstVisit"){

    // first time code
    // ...

    // Create expiring cookie, 2 days from then:
    $.cookie("firstVisit", "1", { expires: 2 });
}
</script>
kolyya
  • 1
  • 1
  • 1