javascript 如何从一个 HTML 文件打开多个选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14371285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:27:39  来源:igfitidea点击:

How to open multiple tabs from one HTML file

javascripthtmlbrowsertabs

提问by lekroif

I work on many computers, which means they use default browser settings(There is no point in changing browser settings, because I will have to do it every time). I need to make an HTML file which will open a specific list of desired pages (think of this as opening all my bookmarks). For example I visit facebook, yahoo, and stackoverflow. I want to click that HTML file, and it will open these 3 sites on the same window (different tabs).

我在许多计算机上工作,这意味着它们使用默认浏览器设置(更改浏览器设置没有意义,因为我每次都必须这样做)。我需要制作一个 HTML 文件,它将打开所需页面的特定列表(将此视为打开我所有的书签)。例如,我访问 facebook、yahoo 和 stackoverflow。我想单击该 HTML 文件,它将在同一窗口(不同的选项卡)上打开这 3 个站点。

Also would functionality like automatic login on all the sites be easy for implementation?

在所有站点上自动登录等功能是否也易于实现?

Attention: Focus on a "portable" solution. Assume that you only have default browser settings. No setting up servers, changing browser settings and things like that. Imagine that you have 200 computers and you can sit on any one of them. You have only a flash-drive with some files on it. I want to click an HTML file, or some script or whatever, so that these pages open in my browser, without triggering the popup blocker.

注意:专注于“便携式”解决方案。假设您只有默认浏览器设置。无需设置服务器、更改浏览器设置等。想象一下,您有 200 台计算机,您可以坐在其中的任何一台上。您只有一个带有一些文件的闪存驱动器。我想点击一个 HTML 文件,或一些脚本或其他东西,以便在我的浏览器中打开这些页面,而不会触发弹出窗口阻止程序。

回答by matthewpavkov

How about using a batch file? I just tried it in Windows 7 with Chrome and it opened all 3 URLs in the same window.

使用批处理文件怎么样?我刚刚在带有 Chrome 的 Windows 7 中尝试过它,它在同一个窗口中打开了所有 3 个 URL。

Make a plain text file with Notepad called file-name.bat. Then add this code:

使用记事本制作一个名为file-name.bat. 然后添加以下代码:

start chrome.exe http://www.google.com
start chrome.exe http://www.yahoo.com
start chrome.exe http://www.microsoft.com

All you should have to do is double click it to run it. You may get a security warning (I didn't).

您所要做的就是双击它以运行它。您可能会收到安全警告(我没有)。

You could check this out too: Batch file for opening one of a list of URLs

您也可以检查一下:Batch file for open a list of URLs

回答by Ethan

<script type='text/javascript'>
(function(){
  //add this line for each website you want to open
  window.open("http://www.facebook.com/",'');
})()
</script>

there are more answers to this question that work here

这个问题有更多的答案在这里工作

回答by Jon Kartago Lamida

Try this example. I hope this something like this is what you want. About popup blocked you have to configure your browser to allow popup opened from this page. The easiest that I know to bypass the popup blocker is put this page inside local server like apache and set your browser to allow popup from localhost.

试试这个例子。我希望这就是你想要的。关于被阻止的弹出窗口,您必须将浏览器配置为允许从该页面打开弹出窗口。我知道绕过弹出窗口阻止程序的最简单方法是将此页面放在本地服务器(如 apache)中,并将浏览器设置为允许从本地主机弹出。

<html>
<script>
function openLinks(){
links = document.getElementsByTagName('a');

 for (i = 0; i < links.length;i++){ 
   window.open(links[i].getAttribute('href'),'_blank');
   window.focus();
 }
}
</script>

<body onload="openLinks()">

<a href="http://google.com">google</a>
<a href="http://stackoverflow.com">stackoverflow</a>
<a href="http://facebook.com">facebook</a>
<!-- add other link -->

</body>
</html>

回答by matthewpavkov

This functionality is built into Chrome. If you don't have to use an HTML file, try just setting your Startup Pages in Chrome's settings. You can add as many pages as you want.

此功能内置于 Chrome 中。如果您不必使用 HTML 文件,请尝试在 Chrome 的设置中设置您的启动页。您可以根据需要添加任意数量的页面。

http://support.google.com/chrome/bin/answer.py?hl=en&answer=95421

http://support.google.com/chrome/bin/answer.py?hl=zh-CN&answer=95421

enter image description here

在此处输入图片说明

回答by user1631686

You could just add window.open(adress) for every page you want to open, or you could use a for loop if you want to open 1 page a specific number of times.

您可以为要打开的每个页面添加 window.open(adress) ,或者如果您想打开 1 个页面特定次数,则可以使用 for 循环。