Window.open cannot open more than two links

According to my requirement, I need to create a Google Chrome extension that opens several links (25+) with one click on different tabs of the same chrome window. The code worked fine until Chrome 18. Now I use chrome 24 and this code stops working. I just saved all the links in an array and opened 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 opened in the tabs, and the rest will be open in different chrome windows. What should I do to overcome this?

Edit # 1

In manifest file

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

The code specified first is in dialog.js

+4
source share
3 answers

Got a solution, hit n touchstones :)

I just deleted the setTimeout function and it works. I still don't understand why this caused the problem.

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

This is apparently a common JavaScript error. setTimeout(window.open(tablink), 500); means calling window.open returns after 500 milliseconds. The return value of window.open is usually a Window object, which results in a setTimeout error, and your code stops executing. This caused a problem. Use setTimout(function(){window.open(tablink)}, 500); .

+1
source

I tried to open the number of sites at a time,

found that "pop-ups were blocked on this page"

you can see it in the address bar.

:)

-2
source

Source: https://habr.com/ru/post/1447148/


All Articles