Search code examples
javascripthtmltimer

Javascript timer - You generated the link "X seconds ago"


How can I make a text display "You generated the link "X seconds ago" after you generate a link. It's part of a website for file-hosting.

I've tried googling, but haven't come to anything that answers my questions.

I'm not even sure if it is Javascript (I'm just assuming!)


Solution

  • use setInterval in order to show the user how many seconds since the link generation:

    HTML:

    <!-- We assume here that the link is already created. -->
    <p>You generated the link <span id="timer"></span> seconds ago</p>
    

    JS:

    var timerSpan = document.getElementById('timer'), seconds = 0;
    setInterval(function() {
        seconds++;
        timerSpan.innerHtml(seconds);
    }, 1000);