> <td><a href="http://Lucifase.com/pages/2000.php?refid=2000"
> target="_blank">2000</a><br></td> <td><a
> href="http://Lucifase.com/pages/3000.php?refid=3000"
> target="_blank">3000</a><br></td> <td><a
> href="http://Lucifase.com/pages/4000.php?refid=4000"
> target="_blank">4000</a><br></td> <td><a
> href="http://Lucifase.com/pages/5000.php?refid=5000"
> target="_blank">5000</a><br></td> <td><a
> href="http://Lucifase.com/pages/6000.php?refid=6000"
> target="_blank">6000</a><br></td>
setTimeout(function() {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0,
false, false, false, false,
0, null);
var links = document.getElementsByTagName('a');
if(links.href.search('refid') >= 0)
links.dispatchEvent(evt);
}, 1000);
But it doesn't work,also don't know how to make them open in new tab one by one.
What do you mean one by one? It appears that "clicking" all of the links at once is okay?
With links, must of the time, just follow the href
instead of trying to send a click event. The following code should open just the tabs you want:
var linksToOpen = document.querySelectorAll ("td > a[href*='refid']");
for (var J = 0, numLinks = linksToOpen.length; J < numLinks; ++J) {
window.open (linksToOpen[J].href, '_blank');
}
Update for OP clarification:
To open the links with a delay between each one is slightly more complicated. Code like this will do it:
var linksToOpen = document.querySelectorAll ("td > a[href*='refid']");
//--- linksToOpen is a NodeList, we want an array of links...
var linksArray = [];
for (var J = 0, numLinks = linksToOpen.length; J < numLinks; ++J) {
linksArray.push (linksToOpen[J].href);
}
openLinksOnDelay (linksArray);
function openLinksOnDelay (linkArray) {
//--- Pop the first link off the array...
var linkToOpen = linkArray.shift ();
if (linkToOpen)
window.open (linkToOpen, '_blank');
//--- Open the next of the remaining links after a delay.
if (linkArray.length) {
setTimeout ( function() {
openLinksOnDelay (linkArray);
},
1000 //--- 1 second. Use 60000 for 1 minute.
);
}
}