4

I am creating a coupons product and would want to open 4 tabs at one button click, this is happening in firefox, but in chrome only 2 links are able to open and the rest two gets blocked.

Here is what I had tried,

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(function() {
    $('[data-popup-open]').on('click', function(e)  {
        window.open('https://www.google.com');
        window.open('http://www.facebook.com');
        window.open('http://www.stackoverflow.com');
        window.open(window.location.href);

    });
});
</script>
</head>
<body>
    <a class="btn" data-popup-open="popup-1" href="#">Open Popup #1</a>
</body>
</html>
  • 2
    If it's only happening in Chrome and not Firefox it could be that Chrome simply blocks websites from opening more than 2 popups. I know that after 2 alerts they ask the user if they'd like to block additional alerts – andrewtweber Apr 27 '16 at 22:57

2 Answers2

3

enter image description here
$(document).ready(function() {

    var linksArray =['https://www.google.com','http://www.facebook.com','http://www.stackoverflow.com'],i;

    $('#open').click(function() {for( i=0; linksArray.length > i; i++){

        window.open(linksArray[i]);
  }
    });
});

Work for me with loop, https://jsfiddle.net/donS/6dcmsg4n/

don505
  • 152
  • 9
  • 6
    Chrome only opens first tab for me... tried 10 solutions every one of them just opens first link not the next... – ied3vil Jun 29 '16 at 13:30
  • 3
    I eventually got this to work once I fully allowed popups in chrome (it was telling me the long list of blocked popups and I didn't see it at first). It seems chrome does indeed start by blocking extra popups from link clicks – Maya Webster Aug 07 '17 at 23:48
  • it just opens one tab – Gajendra Jena Apr 05 '22 at 21:05
  • You need to allow popups in your browser and disable any popup blocking extensions. – don505 Apr 08 '22 at 11:13
0

Try:

window.open("https://www.google.com", '_blank');
Timothy Kanski
  • 1,861
  • 14
  • 20
  • 3
    I wouldn't be surprised if Chrome purposely detects multiple popups per single click and prevents them. They may just max out at 2 per click. – Timothy Kanski Apr 27 '16 at 22:57