0

I would like an automatic popup box to open after the user spends 10 seconds on the page. This is the JavaScript code that I have so far in my HTML document. What can I add to it to make the box appear after 10 seconds?

<script type = "text/javascript">

var modal = document.getElementById('myModal');

var span = document.getElementsByClassName("close")[0];

window.onload = function () {
modal.style.display = "block";};

span.onclick = function() {
modal.style.display = "none";};

window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";} }
</script>
Alex
  • 41
  • 7

1 Answers1

0

You need to learn about setTimeout().

var modal = document.getElementById('myModal');

window.onload = function() {
  setTimeout(function() {
    modal.style.display = "block";
  }, 10);

}

Mirakurun
  • 4,859
  • 5
  • 16
  • 32