No Idea Where To Put Settimeout
So I have very limited knowledge of javascript, so I apologize in advance for my stupidity. I am trying to make it so that these alerts play 16 seconds after the website is initial
Solution 1:
You can use it before the function you declared : playAlert()
So :
let timeInMs = 16000; // set the time in Milisecond here
setTimeout(playAlert("1", 'Images/thankyou.wav'), timeInMs);
Solution 2:
Use the "ready" event of the document. --- This event fires after the DOM has loaded.
function playAllAlerts(){
// do your things
}
document.addEventListener('DOMContentLoaded', function() {
setTimeout(playAllAlerts,16000)); // note playAllAlerts, not playAllAlerts()
});
function playAllAlerts(){
console.log('Thing 1');
console.log('Thing 2');
}
document.addEventListener('DOMContentLoaded', function() {
setTimeout(playAllAlerts,1000); // note playAllAlerts, not playAllAlerts()
});
<div></div>
Post a Comment for "No Idea Where To Put Settimeout"