Reputation: 23
I have a webpage page full of links, with check boxes next to them showing that I've clicked them. There are hundreds of links, and I would rather not click through all of them. What I would like to do is write a script that performs a "click" on each of the links, so that I don't have to.
var links = document.getElementsByClassName("some-class");
for(var i = 0; i < links.length; i++) {
links[i].click();
}
My code simply opens the first link and navigates away from the original page, which of course stops execution of the code.
Can Javascript open links without navigating to them, such as in a new window or tab? If not, with what language can this be scripted?
Upvotes: 1
Views: 1274
Reputation: 320
If opening all the links on a new tab solves your problem you should try the code below.
<a href="https://www.link1.com">First Link</a>
<a href="https://www.link2.com">Second Link</a>
<a href="https://www.link3.com">Third Link</a>
<button id="openAll">Open All</button>
<script>
$("#openAll").click(function(){
$("a").each(function(){
window.open($(this).attr("href"), '_blank');
});
});
</script>
Upvotes: 1