Last Updated: February 25, 2016
·
365
· Andrew Stilliard

Quickly open many links in new tabs (e.g. in phpmyadmin, open each table as a new tab window)

First select the elements you want to loop over:

var elements = document.querySelectorAll('#something a');

Then loop over them making sure the target is "_blank" (for a new tab) and clicking them:

[].forEach.call(elements, function (el) {
  el.target = '_blank';
  el.click();
});

E.g. A use case i had )which would normally be rare) is in phpmyadmin, when inside a database, you could open each table in a new tab by pasting the following into the console:

var elements = frame_navigation.document.querySelectorAll('#subel0 li > a:last-child');
[].forEach.call(elements, function(el) {
  el.target = '_blank';
  el.click();
});