0

I'm building a custom start page for myself and one issue I'm running into is I want to have a link above all sections that, when clicked, will open all pages in a new tab. I've got it parsing through the list, but only the first link opens in a new tab, all the others open in new windows.

Here's a link to the page I'm working on:
https://dl.dropboxusercontent.com/u/114859/code-experiments/start-tab.html

Here's an HTML snippet of an example section:

<section>
  <h2>Wallpaper Sites (<a href="#">open all</a>)</h2>
  <ul>
    <li><a href="http://wall.alphacoders.com/">Alpha Coders</a></li>
    <li><a href="http://interfacelift.com/">InterfaceLIFT</a></li>
    <li><a href="http://thepaperwall.com/">The Paper Wall</a></li>
  <ul>
</section>

Here's the JavaScript (mostly jQuery):

$( 'h2 a' ).on( 'click', function ( event ) {
  event.preventDefault();
  event.stopPropagation();
  $( this ).parent().next().find( 'a' ).each( function () {
    // console.log( this.href );
    window.open( this.href );
    window.focus();
  });
});
dougoftheabaci
  • 665
  • 1
  • 6
  • 19
  • Related: http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript – Ord Jul 27 '14 at 19:30
  • That's for a single link, which already works with what I'm doing. – dougoftheabaci Jul 27 '14 at 21:08
  • If you look at the answers to that question, though, the consensus seems to be: "browsers can choose to open a link in a new tab or a new window, and there's very little you (as a javascript programmer) can do about it". Which does seem relevant to this question. – Ord Jul 28 '14 at 02:05

1 Answers1

1

Im not sure if this kind of behavior doesn't depand on your/user's google chrome settings.

Matúš Bartko
  • 2,425
  • 2
  • 30
  • 42
  • I don't see how, it seems weird that the first would open in a tab but each subsequent one would open in a new window. – dougoftheabaci Jul 27 '14 at 21:06
  • Hello Matus, just as feedback, this is a comment, it is not an answer, consider to use the "add a comment" option in the future. – jtorrescr Jul 27 '14 at 21:25
  • Yes, I`m sorry about this, but as far as I know, there is not really an answer :( but you are right, I should have comment it. – Matúš Bartko Jul 27 '14 at 21:31