I have combined onclick event with window opener function but the codes are messing up and not opening windows as per the given time 5 seconds
I want to open all windows exact after 5 seconds
one by one no matter how many windows are there.
here is my JSFiddle
let newWindow = null;
function openLink(link){
if(newWindow === null){
newWindow = window.open(link, '_blank');
}
else{
newWindow.location.href = link;
}
}
flink.onclick = function() {
openLink('https://www.baidu.com');
setTimeout(() => openLink('https://www.reddit.com'), 5000);
setTimeout(() => openLink('https://www.youtube.com'), 5000);
setTimeout(() => openLink('https://www.stackoverflow.com'), 5000);
}
<a id="flink" href="javascript:void();" onclick="openLink();">Visit Link</a><br>