Forum Moderators: open
Does anyone know of a way to have a different text link (from a list of links) be displayed with every visit to a page? In other words, I have a list of links in a file. When someone visits mt homepage I would like to have one of the links in the file be displayed on the page. If the user clicks the refresh button or surfs away and returns to the page, a different link will be displayed.
The links would look and act like normal links except for the fact that a different link is displayed each time the page is visited. Any help will be greatly appreciated.
Thanks
The idea would be to have an external js file that creates an array where each element would be a different URL. You would have a randomizing function pick one array element and assign it to a variable. Then use document.write() to insert that URL into your HTML page.
But if this is a long list of links then building the array will make for a slow page. In that case, or if you're concerned about visitors with no javascript, you'd want to turn to some server side scripting -- which is outside the scope of this forum.
Depending on what your server has available you could get good input either from our Perl and PHP CGI Forum [webmasterworld.com] or our Microsoft .NET and ASP Forum [webmasterworld.com].
Just make sure to provide one link in a <noscript> tag for the JS disabled and I think you'll be fine doing it client-side.