Last Updated: February 25, 2016
·
608
· 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();
});

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside