简体   繁体   中英

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 . 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 .

Step 1 : Create a new file, say, in same folder as of index.html . (let's say temp.html ).

Step 2 : Now in the JavaScript code index.html , write :

$('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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM