1

I want to open google and youtube in one click. But the tricky part here is, I want it to be open in a new window. I already achieved it on tab. But my client don't want to open in tab. So I need to change it on new window.

Here's what I've tried so far.

<a href="#" id="linkTrigger">Open Links</a>

var trigger = document.getElementById('linkTrigger'),
    link = ['www.google.com', 'www.youtube.com'];

trigger.onclick = function {
    [].forEach.call(link, function(e){
        if(e == 'www.google.com')
            window.open(e, 'newwindow', 'height: 100px, width: 100px');
        else 
            window.open(e);
    });
}

I also read that window.open(/* link */, _blank) should open in a new window, However, for me. It's opening in new tab. I'm currently using Google Chrome 49.

The script can just open google as we expected.

I searched for possible solutions but there's no the same problem with me.

Any help would be appreciated. Thanks!

hdotluna
  • 5,514
  • 4
  • 20
  • 31

2 Answers2

-1

Use "_blank" as first parameter to window.open(), "width=/*height*/,height=/*width*/" as third parameter, then setting location.href of opened window

var w = window.open("_blank", "w", "width=600, height=400"); 
w.location.href = "http://www.google.com";
guest271314
  • 1
  • 15
  • 104
  • 177
-1

there is a full topic about how to do it and what problems with opening urls in new tabs are.

Here is the link: Open a URL in a new tab (and not a new window) using JavaScript

hope this helps, Regards

Community
  • 1
  • 1