3

My objective is to open two URLs in two tabs with just one click with a single link.

So far I have tried two javascript codes (found in this forum that attemps to open 3 URLs) and a jquery code.

It seems that Internet Explorer and Mozilla in their default settings allow this to happen. While in Chrome, I am getting the pop-up blocker. I know that it would be just a matter of allowing the pop-up to happen in chrome in order for the multiple links to open, but it would be a huge advantage for the experience I am trying to build, to have all browsers providing same user experience: one click, two URLs opened in two tabs.

Is there any workaround as of now that you might know that avoids getting the pop-up blocker in Chrome?

Below there are two the javascript codes and the jquery one that I have been testing. All of them have the same effect in chrome triggering, and succeed in Internet Explorer and Mozilla.

I thank you in advance.

JAVASCRIPT

 <a href="#" target="_blank" onclick="window.open('http://google.com');
    window.open('http://yahoo.com');" >Click to open Google and Yahoo</a>




<a href="http://bloggersentral.blogspot.com/" target="_blank"
       onclick="window.open(&quot;http://www.tourism.gov.my/&quot;);
       window.open(&quot;http://www.tic.kelantan.gov.my/&quot;);">This anchor opens three links in a single click</a>

JQUERY

<body>
    <a href="" class="each">Click</a>
  <script>
    $('.each').click(function() {
        var urlList = "http://www.google.com,http://www.yahoo.com"
 $.each( urlList.split( "," ), function( index, item ) {
 window.open( item, "_blank" )
 });
        })


   </script>
   </body>
jophab
  • 5,356
  • 14
  • 41
  • 60
  • Why do you want to open two tabs with one click? – Phil Jul 09 '15 at 20:48
  • I am not trying to hack anyone's browser, I just need corelated URL's to open at the same time. I might look as well how to open two URL's in one window if that is regarded as a better practice. What do you think? – Arturo Rosales Baez Jul 09 '15 at 21:00
  • I think that technique goes against every hci rule in the book. Consider making a list of correlated links for the user to click rather than forcing the user to open them all at once. – Phil Jul 09 '15 at 22:29

3 Answers3

1

The user has to manually allow the popups because otherwise it would mean that there could be a whole lot of spam websites. So no.

But also here is a very simple html code for it

<a href="http://www.microsoft.com" target="_blank" onclick="window.open('http://www.google.com'); window.open('http://www.yahoo.com');">Click Here</a>

You could ask the user to disable it: How do I detect popup blocker in Chrome?

Community
  • 1
  • 1
Cynigo
  • 374
  • 2
  • 11
0

I think the only way to prevent pop up blocker blocking popups is that the user says "allow popups for this page". Otherwise this would be a security issue.

Stephan Ahlf
  • 3,310
  • 5
  • 39
  • 68
0

If there was an easy workaround to the popup blocker than it wouldn't do a very good job at blocking popups, would it? The best solution in this scenario would either be to separate the links into two separate clicks, or inform the user that they may have to manually allow the tabs to be opened if they have a popup blocker enabled. So in short. No, you can't but there are plenty of better ways to approach the issue.

Austin Philp
  • 94
  • 1
  • 10