Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.70 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do I select and open a random link of a certain class on an external webpage?
  2. var linksInCategory = document.$('.CategoryTreeLabel').href);
  3. var randomLinkArray = Array(linksInCategory);
  4.        
  5. function goThere(link) {
  6.     var the_url = randomLinkArray[Math.floor(Math.random()*randomLinkArray.length)];
  7.  
  8.     var new_window = window.open(the_url,"new_window","menubar, resizeable. location, toolbar, status, scrollbars");
  9. }
  10.        
  11. </script>
  12.     </head>
  13.     <body>
  14.         <form name="the_form">
  15.             <input type="button" name="randomSportsArticle" class="broadGroups" onClick="goThere(this)" src="http://en.wikipedia.org/wiki/Category:Sports" value="Sports"></input>
  16.  
  17.         </form>
  18.     </body>
  19. <html>