0

I have an array which selects one of two links. When the button is pressed it opens one of the URLs that are in the array, I'd like it to open in a new tab but currently, it isn't. I had added the code below. Any help would be much appreciated.

Javascript:


    
        function randomlinks(){
            var myrandom=Math.round(Math.random()*1)
            var links=new Array()
            links[0]="http://link1.com"
            links[1]="http://link2.com"                

            window.location=links[myrandom]
    }
    

HTML:

  input onclick="randomlinks()" type="button" value="Click Here!"
Oliver
  • 1
  • 1
  • Hi @CalvinNunes, I have tried to implement this but it hasn't worked for me. Cheers – Oliver Jan 08 '20 at 20:29
  • If you read the first answer of the duplicated one, you'll see that you can't control if the page will be opened in a new tab or new window. Also "*...but currently, it isn't.*" What it means? nothing is happening at all or what? – Calvin Nunes Jan 08 '20 at 20:32
  • @CalvinNunes — That's about forcing a new tab instead of a new window. This question is about using a new tab instead of the same tab. (Although it is possible to infer the answer from there, which is to use `window.open(url)` instead of `window.location=url`). – Quentin Jan 08 '20 at 20:44

0 Answers0