I want to have a bunch of different ads, that I create, and have a random one of them load each time someone goes to that page. Is there a way to do this?
If this is for banners, and you want to ensure fair rotation, here is an in-depth article for a script that will do this for you. It will appear random to the end user, but it will ensure even exposure of the random items: http://www.iwdn.net/showthread.php?t=3414 If you're not concerned with even exposure, and variety is all that's needed, here's a VERY simple script and some discussion about it. I'm using it in one site to deliver a "Tip of the Day" type of thing. http://www.iwdn.net/showthread.php?t=3349 The nice thing about these scripts is that they are very easy to use, and since they do not rely on JavaScript, you don't have visitors missing out on their contents, and search engines will pick up on them much better. Plus, you don't have to create <noscript> alternatives.
Here is a simple code that will display a randum banner each time page is loaded. part1 place it between <head> and </head> <script language="JavaScript"> <!-- // Set up the image files to be used. var theImages = new Array() // do not change this // To add more image files, continue with the // pattern below, adding to the array. Rememeber // to increment the theImages[x] index! theImages[0] = '100.jpg' theImages[1] = 'acc.jpg' theImages[2] = 'xyz.jpg' theImages[3] = '10s0.jpg' theImages[4] = 'ascc.jpg' theImages[5] = 'xyzs.jpg' // ====================================== // do not change anything below this line // ====================================== var j = 0 var p = theImages.length; var preBuffer = new Array() for (i = 0; i < p; i++){ preBuffer[i] = new Image() preBuffer[i].src = theImages[i] } var whichImage = Math.round(Math.random()*(p-1)); function showImage(){ document.write('<img src="'+theImages[whichImage]+'">'); } //--> </script> Code (markup): part 2: place it between <body></body>tags at your desired place <script language="JavaScript"> showImage(); //--> </script> Code (markup): You can modify it as per your requirement.
yes its working for images, but not for html docs. Im pretty new to this, so maybe im doing somthing obviously wrong. Should it work for html docs?
The method I linked to can rotate any code. It randomly inserts from different lines of a .txt file. You may have to edit some of your code to make it appear on one line, but this is a simple matter of clicking "end" "delete" down end delete... unless you have a tool that removes extra white space. If even rotation is important, I really haven't looked at the issues pointed out by the_pm.
The biggest issue with all of the methods in use here, with the exception of those jazzylee77 and I posed, is that they rely on the client to produce results. This means someone with JavaScript disabled or not available will not receive the desired effect. Furthermore, you lose whatever edge you might have otherwise gained from search engines by having images they can index and alt text they can read. Given the fact that PHP rotators are lean and handled at the server instead of the client, it's hard to fathom even considering a different option. Here's a version I sent to OP via private message: http://www.paulhirsch.com/ex/random_rotation/ The rotator.php file shows the whole thing in action. The .zip file gives you the whole thing you can play with on your own.