SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Jan 12, 2007, 07:26 #1
- Join Date
- Dec 2006
- Location
- NL
- Posts
- 11
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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>
*note: I don't know much about javascript
-
Jan 12, 2007, 07:38 #2
- 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, "", "");
-
Jan 12, 2007, 07:57 #3
- 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)
-
Jan 12, 2007, 08:04 #4
- 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!
-
Jan 12, 2007, 08:21 #5
- Join Date
- Dec 2006
- Location
- NL
- Posts
- 11
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
lol, thanks again
Bookmarks