How to insert cookie in this code

0

People I have a code that makes a link stay green for 10 seconds and then it turns blue, the only problem is that if I refresh the page within 10 seconds it comes back all over again. So I wanted to know how to make the action continue where it left off even after updating, see the code:

<a id="id1" href="https://br.answers.yahoo.com" onclick="myFunction(event)" target="_blank">Clique Aqui</a> <br/><br/>

<script language="javascript">
    function myFunction(s) {
        var id = s.target.id;

        document.getElementById(id).style.color = "green";
        setTimeout(function(){
            document.getElementById(id).style.color = "blue";
        }, 10000);
    }
</script>
    
asked by anonymous 02.05.2016 / 16:27

1 answer

1

If you want it to continue indefinitely until you delete it, you can do this with html5, or if you want to forget the data when closing the browser as well.

UNDEFINEDLY: // Store

localStorage.setItem("lastname", "Smith");

// Receive

var lastname = localStorage.getItem("lastname");

// Remove

localStorage.removeItem("lastname");

TEMPORARILY // Store

sessionStorage.setItem("lastname", "Smith");

// Receive

var lastname = sessionStorage.getItem("lastname");

// Remove

sessionStorage.removeItem("lastname");
    
03.05.2016 / 13:39