How to update javascript code every 5 seconds? [closed]

0

How to update this code every 5 seconds ?. I need that when the user changes his fingerprint, the code is updated without the need to update the page, and that the cookie with the value of the new fingerprint is created.

<center> Tu Huella Digital es: <div id="fp2"></div></center>
  <script src="fingerprint/fingerprint.js"></script>
<script>
  var fp2 = new Fingerprint({canvas: true});
  document.getElementById('fp2').innerHTML = fp2.get();
</script>
<script>
  var fn = document.getElementById('fp2').innerHTML;
  var cookieName = 'fingerprint';
  var cookieValue = fn;
  var myDate = new Date();
  myDate.setMonth(myDate.getMonth() + 12);
  document.cookie = cookieName +"=" + cookieValue + ";expires=" + myDate;
</script>
    
asked by Luis Cesar 18.11.2018 в 15:31
source

1 answer

1

In Javasctipt there is a method to launch a function every x time. It is called setInterval (), which receives two parameters; first the function you want to run periodically, and second the time in milliseconds how often you want to run it. In your case 5,000 milliseconds. The syntax is like this:

setInterval ('tuFuncion ()', 5000);

I hope it serves you for what you are looking for.

    
answered by 18.11.2018 в 19:39