Click to See Complete Forum and Search --> : Rotate Random Div Layers on Page Refresh?
joeystacks
04-14-2007, 02:39 PM
Does anyone know of a scipt that will rotate random div layers on page
refresh? I have a primary content area front and center on my site
homepage, and I'd like to rotate various chunks of html (in div
layers) each time a user reloads the page. Right now I'm resorting to
a random image rotation (those scripts are a dime a dozen) on refresh,
but it's far from ideal for what I'm trying to accomplish. Any help
on this would be GREATLY appreciated!
This is far better delivered from server side script as the only way to persist data on the client side (ie: know when a banner has been shown and when) is via cookies and that is not reliable enough unless you have complete control over the delivery environment.
If however you were to deliver it from the server side there would be numerous benefits, such as being able to read a lot of the metrics from your visitor (ie: want to only deliver certain banners depending on the location of the user? Easy, check the IP - something that can't be done client side* - and if they are in, for example, Saudi Arabia then don't serve them that banner about the latest cold beers) and you would also be able to hold the data for the banners in one central location (a database or flat file xml on the server) rather than have all the code in every page you send.
* you can check IP on the client, I believe, by instantiating the java object in Gecko browsers, but I wouldn't rely on that.
joeystacks
04-14-2007, 03:25 PM
Thanks for the feedback. I really want to use this script more for light-weight front-end content, then anything server side. It's more for showing a slick graphic splash with html text layered on top (marketing) than anything else.
If you still want to do this client side only then google for "javascript setCookie getCookie" and you should find some fairly generic js to store and retrieve cookies client side.
If you don't know, a cookie is a simple text string that can have key/value pairs added to it. Those methods mentioned above will provide a quick way to set/get them.
konithomimo
04-14-2007, 08:04 PM
Well, the best way is server-side, but I will answer the original question before giving other solutions. Client side you really only have a few options. If you want to remember what content the user has already seen, then you will have to use cookies. To switch the content you can either hard code the divs into the page and then display the desired one as necessary onload, or you can store the content into an array and dynamically create the div to show. either way, make sure that you have a default div already showing, so that users without JS enabled can still view the content.
The next thing you can do client side, is to use AJAX/XML with JS to show the content. This way you can store your content in XML files and then display an XML file.
The best thing though is to use a server side language such as PHP so that you can use sessions/cookies to store the data so that you dont show the same person the same content over and over, or you can decide to not use cookies (since some users dont have them enabled) and temporarily store the content shown for each IP on your server in a DB, or more practically in a text file.
joeystacks
04-17-2007, 08:44 PM
Ok this is getting way over-complicated. Guys! The purpose of my posting wasn't to over-engineer this. I just need a simple client-side javascript that rotates Div IDs on refresh. I'm not trying to do something amazing with cookies, XML, etc. If you choose to respond, please do not be concerned with the "strategy" I should be using to implement this. I'm building a simple static site prototype as part of a business plan, that's it. I have 3 marketing messages I want to rotate on refresh on the homepage. I want to use graphics and html text in those marketing messages. The messages target anyone and everyone that hits the page, so I'm not concerned with cookies or XML or databases or any of that.
I hope this helps to clarify things.