What's Here?
- Members: 117,577
- Replies: 431,938
- Topics: 66,689
- Snippets: 2,395
- Tutorials: 631
- Total Online: 2,171
- Members: 61
- Guests: 2,110
Who's Online?
|
Welcome to Dream.In.Code |
|
Getting Help is Easy!
Join 117,577 Programmers for FREE! Ask your question and get quick answers from experts. There are 2,171 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
Displays a random link (or image, or paragraph, or anything from that matter!) on a web page.
|
Submitted By: spearfish
|
|
Rating:
   
|
|
Views: 440 |
Language: JavaScript
|
|
Last Modified: April 2, 2008 |
Instructions: As always, this is formatted in a nice HTML document :-)
You will need to modify the array "links" to suit your needs.
Open up a script and call function disp_links(number) to bring in the links wherever you want them. The parameter is the number of links you want displayed. They will be brought in as they are listed in the array, so if you plan to pull multiple links, be sure to put a space or a after each of the elements of the array.
Any HTML you're storing as an array element must use single quotes.
Also, you can use ANYTHING with this script, not just links. Whatever HTML you store as an array element (including pictures, paragraphs, linked pictures) will be brought out to wherever the function is called from.
-Spear |
Snippet
<html>
<head>
<title>LINK_RAND</title>
<script type='text/javascript'>
var links=new Array();
links[0]="<a href='http://www.yahoo.com/'>Yahoo</a> ";
links[1]="<a href='http://www.dreamincode.net/'>Dream.In.Code</a> ";
links[2]="<a href='http://www.example.com/'>Example.com</a> ";
links[3]="<a href='http://www.conquerclub.com/'>Free online risk!</a> ";
links[4]="<a href='http://www.google.com/'>The best search engine in the world</a> ";
function disp_links(number) {
for (i=1;i<=number;i++) {
var k = Math.floor(Math.random()*links.length);
document.write(links[k]);
}
}
</script>
</head>
<body>
<p><script type='text/javascript'>disp_links(1);</script></p>
</body>
</html>
Copy & Paste
|
|
|
Programming
Web Development
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|