SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Location
    NL
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question random url/link opener, help needed

    I have the following script in the body of my "linkpage"
    this works fine ... except i would like it to open a random url in a new window ... is this possible with window.open???

    HTML Code:
    <script>
    function random_all(){
    var myrandom=Math.round(Math.random()*(document.links.length-1))
    window.location=document.links[myrandom].href
    }
    </script>
    working example

    *note: I don't know much about javascript

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes,
    Code:
    window.open(document.links[myRandom].href, "", "");

  3. #3
    SitePoint Member
    Join Date
    Dec 2006
    Location
    NL
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello, thank you for your quick reply
    I added your piece of script, but when I click my image.gif nothing happens???

    HTML Code:
    <script>
    function random_all(){
    var myrandom=Math.round(Math.random()*(document.links.length-1))
    window.open(document.links[myRandom].href, "", "");
    }
    </script>
    
    <img src="image.gif" onClick="random_all()" class="random" alt="random link" width="50px" height="60px" border="none">

    (working in FF on XP)

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, you seem to have pasted in my code that uses myRandom, while your original code had myrandom. My bad. Just pick one of them (myrandom or myRandom), update the script and voila!

  5. #5
    SitePoint Member
    Join Date
    Dec 2006
    Location
    NL
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol, thanks again


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
  •