window.open无法打开两个以上的链接 [英] window.open not not able to open more than two links
问题描述
根据我的要求,我需要创建一个Google Chrome扩展程序,只需在一个Chrome窗口的不同标签中单击即可打开多个链接(25+)。代码在Chrome 18之前工作正常。现在,我正在使用chrome 24并且代码停止工作。我只是将所有链接存储在数组中并使用for循环打开它们,如下所示:
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?
编辑#1
在我的清单文件中
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["script.js", "jquery.js", "dialog.js"]
}
],
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
首先给出的代码是dialog.js
The code given first is in dialog.js
推荐答案
得到解决方案,点击试用版:)
Got the solution, hit n trial rocks :)
我刚删除了setTimeout函数,它可以工作。我仍然不知道它导致问题的原因。
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);
}
}
这篇关于window.open无法打开两个以上的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!