0

This is my script placed above the </body>. It shows every time a user visits a link on my blog. I want it to display only once a day not to annoy my visitors. I experimented for a couple of days but could not achieve my goal. If anyone can please help?

<div class='demo-float'>
<span class='df-hide'><i class='fas fa-times'/></span>
<div class='df-logo'/>
<h3>Social Media Masterplan</h3>
<p class='excerpt'>Easy to follow Social Media post ideas designed to grow your business and give you competitive advantage.</p>
<a class='button download colored-button' href='https://vandeweybalao.blogspot.com/2020/06/social-media-content-calendar-for-busy-entrepreneurs.html' target='_blank' title='Social Media Masterplan Toolkit'>DOWNLOAD TOOLKIT</a>
</div>
<script type='text/javascript'>
$(function(){$(&#39;.df-hide&#39;).on(&#39;click&#39;,function(){$(&#39;.demo-float&#39;).fadeOut(170);});});
</script>
Vantimist
  • 1
  • 3
  • Does this answer your question? [Making my javaScript popup to appear only once](https://stackoverflow.com/questions/23775440/making-my-javascript-popup-to-appear-only-once) – Alexandre Elshobokshy Aug 27 '20 at 07:38

1 Answers1

1

Depending on how your application is composed, there are two ways of dealing with it. In case your application does not have a server-side, you can use localStorage property(global object) in js, to check, whether or not the user has visited your page in the current day. The way of doing it is:

function hasOneDayPassed(){
  var date = new Date().toLocaleDateString();

  if( localStorage.getItem("savedDate") == date ) 
      return false;

  localStorage.setItem("savedDate", date);
  return true;
}

function runOncePerDayMyCode(){
  if( !hasOneDayPassed() ) return false;

  // your code below
  document.getElementById("myDiv").style.display = "block";//or whatever
}


runOncePerDayMyCode();

If the application has a server-side, you can save logs like Ip address and DateTime(or login credentials), and based on your backend information, you show or not the extra content

Shpend Palushi
  • 597
  • 8
  • 21