2

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.

2
  • 1
    The window object in your code represents the current window. So whenever you use window.open it can only create a new tab in the current window or a fresh new window. But you cannot create a tab in the newly created window Commented Sep 28, 2020 at 5:00
  • As far as I know, this is not possible in javascript. Check this answer Commented Sep 28, 2020 at 5:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.