SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Guru scotlandforvisit's Avatar
    Join Date
    Aug 2004
    Location
    Scotland
    Posts
    687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    opening in new page

    I am trying to get this script to open the random page in a new window/tab. Not having much luck. Suggestions gratefully received.


    <!--
    /*
    Random link button- By JavaScript Kit (http://javascriptkit.com)
    Over 300+ free scripts!
    This credit MUST stay intact for use
    */

    //specify random links below. You can have as many as you want
    var randomlinks=new Array()

    randomlinks[0]="http://www.buildingapc.co.uk/index.php"
    randomlinks[1]="http://www.buildingapc.co.uk/hardware.php"
    randomlinks[2]="http://www.buildingapc.co.uk/harddisk.php"
    randomlinks[3]="http://www.buildingapc.co.uk/memoryfit.php"
    randomlinks[4]="http://www.buildingapc.co.uk/processor.php"

    function randomlink(){
    window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
    }
    //-->
    </script>
    <form>
    <p><center><input type="button" name="B1" value="Random Link >" onclick="randomlink()"></center></p> </form>

    <!--Uncomment below to use a regular text link instead
    <a href="javascript:randomlink()">Random Link</a>
    -->
    The newest sites in the online empire!Scotlands Culture
    Baby Names

  2. #2
    SitePoint Addict
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like you're missing a ; at the end of your js lines.
    Also, I believe the correct syntax is window.location.href not window.location but you mentioned that you want to open a new window so that could work like this:
    Code:
    window.open(randomlinks[Math.floor(Math.random()*randomlinks.length)]);

  3. #3
    SitePoint Guru scotlandforvisit's Avatar
    Join Date
    Aug 2004
    Location
    Scotland
    Posts
    687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    that worked a treat. Thanks for your very quick response
    The newest sites in the online empire!Scotlands Culture
    Baby Names


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •