How do you open a random link in a new window?

Discussion in 'JavaScript' started by bobocheez, Jul 10, 2010.

  1. #1
    How would you integrate the following? It would be great if the random URL would open in a new window.

    function randomlink(){
       window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
       }
    function open_win(url_add)
       {
       window.open(url_add,'welcome',
       'width=300,height=200,menubar=yes,status=yes,
       location=yes,toolbar=yes,scrollbars=yes');
       }
    Code (markup):
     
    bobocheez, Jul 10, 2010 IP
  2. tdemetri

    tdemetri Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    like this:
    <html>
    <head>
    
    <script type="text/javascript">
    
    var randomlinks=["http://www.google.com", "http://www.yahoo.com", "http://www.aol.com"];
    var url_add=randomlinks[Math.floor(Math.random()*randomlinks.length)];
      
    function open_win()
       { url_add=randomlinks[Math.floor(Math.random()*randomlinks.length)];
       window.open(url_add);
       }
    </script>
    </head>
    
    <body>
    <input type="button" value=" Open a random link in a new window " onclick="open_win()" />
    <h2>google</h2>
    <h2>yahoo</h2>
    <h2>aol</h2>
    </body>
    </html>
    Code (markup):
     
    tdemetri, Jul 10, 2010 IP