Search code examples
javascriptjqueryhtmlgoogle-chromegoogle-chrome-extension

window.open not not able to open more than two links


As per my requirement, i need to create a Google Chrome Extension which opens multiple links (25+) on a single click in different tabs of a single chrome window. The code was working fine earlier till the Chrome 18. Now, I am using chrome 24 and that code stopped working. I was simply storing all the links in an array and opening them using a for loop as follows:

  for(var i = 0; i<links.length; i++)
  {
    var tablink = links[i];
    if(links[i] != "")
    {
            tablink = *"somedomain"* + tablink;
        setTimeout(window.open(tablink), 500);  
    }
  }  

As a result, only two links were open in tabs and rest will open in different chrome windows. What should i do to overcome this?

Edit #1

In my manifest file

"content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "js": ["script.js", "jquery.js", "dialog.js"]
    }
  ],


"permissions": [
    "tabs", "http://*/*", "https://*/*"
  ],

The code given first is in dialog.js


Solution

  • Got the solution, hit n trial rocks :)

    I just removed setTimeout function and it works. I still don't why it was causing the problem.

    for(var i = 0; i<links.length; i++)
      {
        var tablink = links[i];
        if(links[i] != "")
        {
                tablink = *"somedomain"* + tablink;
            window.open(tablink);  
        }
      }