Open many links at once in Safari

safaritabsweb-browsing

Can several links be opened at once in Safari?
Imagine you are on a page with a lot of links:

enter image description here

Would it be possible to select all the links and open them all in one single Command-click? As such:

enter image description here

I am often finding myself Command-clicking links for dozens of minutes a day, and wishing I could open more links all at once. Surely I'm not the only person in this situation!

Best Answer

There is a way to do something close - it involves adding a bookmarklet to Safari and selecting that once you're on the page.

However, this will either open only the hyperlinks you've selected (i.e. highlighted) on the page or it will open all hyperlinks found on the page if you haven't highlighted any. In other words, it doesn't work in the Command + click manner you want.

If you're interested, here's the process to set this up:

  1. Visit any page using Safari
  2. Press CommandD to add a bookmark to the page you just visited
  3. In the highlighted field that appears in the window, change the text to something like Open all hyperlinks
  4. Press OptionCommandB to edit bookmarks
  5. Find the bookmark you just added and right-click on it
  6. Select Edit Address... from the context menu
  7. This should highlight the URL. Press Delete to remove it
  8. Now paste the following code where the URL was previously:

javascript:(function(){var n_to_open,dl,dll,i; function linkIsSafe(u) { if (u.substr(0,7)=='mailto:') return false; if (u.substr(0,11)=='javascript:') return false; return true; } n_to_open = 0; dl = document.links; dll = dl.length; if (window.getSelection && window.getSelection().containsNode) { /* mozilla */ for(i=0; i<dll; ++i) { if (window.getSelection().containsNode(dl[i], true) && linkIsSafe(dl[i].href)) ++n_to_open; } if (n_to_open && confirm('Open ' + n_to_open + ' selected links in new windows?')) { for(i=0; i<dll; ++i) if (window.getSelection().containsNode(dl[i], true) && linkIsSafe(dl[i].href)) window.open(dl[i].href); } } /* /mozilla */ if (!n_to_open) { /*ie, or mozilla with no links selected: this section matches open_all_links, except for the alert text */ for(i = 0; i < dll; ++i) { if (linkIsSafe(dl[i].href)) ++n_to_open; } if (!n_to_open) alert ('no links'); else { if (confirm('No links selected. Open ' + n_to_open + ' links in new windows?')) for (i = 0; i < dll; ++i) if (linkIsSafe(dl[i].href)) window.open(dl[i].href); } } })();

  1. Press Return to accept the code

To make this work, open any page in Safari and then select the bookmarklet. One of the following things will happen:

  • if you haven't highlighted any hyperlinks on the page, the code will proceed to open all hyperlinks in a separate tab
  • if you've highlighted x number of hyperlinks, then the code will proceed to open those selected hyperlinks in separate tabs

IMPORTANT: If this doesn't work for you, ensure that you have Javascript enabled. You can do this via Safari > Preferences > Security.

One more thing - I have tried many times to get the above javascript to work as a Service in Safari (thinking that would be better than the bookmark approach), but have never been able to get it to work. On the off-chance you do, please share how. :)