[英]How to open new window with multiple tabs with javascript?
I would like to open a link in a new window that opens multiple tabs.我想在打开多个选项卡的新窗口中打开一个链接。 Currently, I am able to to open multiple tabs in the same window;
目前,我可以在同一个窗口中打开多个选项卡; this looks something like:
这看起来像:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('http://yahoo.com');
window.open('http://google.com');
So clicking a link of class 'yourlink' will open multiple links on the same window.因此,单击“您的链接”类的链接将在同一窗口中打开多个链接。 For doing the same thing, but in a new normal window, I have tried using the following jquery arguments
window.open('url', 'window name', 'window settings')
in the first window.open
.为了做同样的事情,但在一个新的普通窗口中,我尝试在第一个
window.open
使用以下 jquery 参数window.open('url', 'window name', 'window settings')
。 However this only makes one link open in a new window, and also in an undesirable format.然而,这只会在新窗口中打开一个链接,而且格式也不理想。
You can achieve that, by doing this :你可以做到这一点,通过这样做:
Let's say that your current file is index.html
.假设您当前的文件是
index.html
。
Step 1 : Create a new file, say, in same folder as of index.html
.第 1 步:在
index.html
文件夹中创建一个新文件。 (let's say temp.html
). (假设
temp.html
)。
Step 2 : Now in the JavaScript code index.html
, write :第 2 步:现在在 JavaScript 代码
index.html
,写入:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('./temp.html', '_blank', 'location=yes,scrollbars=yes,status=yes');
});
This will open a new window.这将打开一个新窗口。
Step 3 : Just add script
tag in temp.html
, and write following code inside it:第 3 步:只需在
temp.html
添加script
标签,并在temp.html
编写以下代码:
var links = ['http://yahoo.com', 'http://google.com'];
for(let i = 0 ; i < links.length ; i++){
window.open(links[i]);
}
window.close();
In the array, put all the links you want to get opened.在数组中,放入所有要打开的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.