0

I have an array of Strings which are the directoriess of my pdfs such as:

var fluids_array = ["Fluid/no1.pdf", "Fluid/no2.pdf"];

for(var i in fluids_array) {
        var fluidplan = fluids_array[i];        

        var myWindow = window.open(fluidplan,"_blank");

        if (myWindow) {
            myWindow.focus();
        }
    }

Why does it only opens the last (second) pdf and not both? How can I fix it?

moody
  • 404
  • 7
  • 19
  • I have tried same thing but for me only 1st pdf was opening and not 2nd one. Then i noticed that 2nd pdf is blocked by chrome. then i have given the permissions to allow popups and things are working for me now. – Chetan Sep 16 '16 at 12:47

1 Answers1

0

I tried your snippet with 2 urls into the array. This code opens correctly both, obviously browser can focus just one window at once.

Some tips if really the first file has not been opened:

  • Check if the file actually exists
  • Which browser are you using? Probably you should specify an identifier for the opened window, else it could try to open both in the same window or tab. Check this: http://www.w3schools.com/jsref/prop_win_name.asp
xyzale
  • 745
  • 8
  • 14
  • hey hey, i am using chrome and the problem was the chrome-ad-blocker – moody Sep 16 '16 at 12:28
  • @xyzale I have tried without focusing on window. It still opens only one window. – Chetan Sep 16 '16 at 12:30
  • So strange. I'm using Chrome as well. However I had a similar issue. Browsers don't like when windows are opened by js without a direct action from the user. I suggest to find a different solution if you want to be sure all browsers behave as you like. – xyzale Sep 16 '16 at 12:42
  • same thing working for me @xyzale now previously i was chrome, who was blocking popups. I have just given permission and it working now – Chetan Sep 16 '16 at 12:45