1

I would like to add a delay for this code including the async and the data attributes.

<script async src="https://s.widgetwhats.com/wwwa.js" data-wwwa="1"></script>

I saw this solution on stackoverflow enter link description here but it doesn't include the parameters.

Uri Gross
  • 484
  • 1
  • 8
  • 20

1 Answers1

2

script with async attribute means it will be executed as soon as it is downloaded, regardless of whether the rest of the page is loaded.

If you want a delay before loading the script, you can remove the async attribute and use the setTimeout function to delay the execution like the following way:

<script>
  setTimeout(function() {
    var script = document.createElement('script');
    script.src = "https://s.widgetwhats.com/wwwa.js";
    script.setAttribute('data-wwwa', '1');
    document.body.appendChild(script);
  }, 2000); //delay in milliseconds (2 seconds)
</script>
Mamun
  • 66,969
  • 9
  • 47
  • 59