Forum Moderators: open

Message Too Old, No Replies

Displaying a different link each time

         

rlrouse

3:29 pm on Feb 16, 2003 (gmt 0)

10+ Year Member



Hello,

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

tedster

11:29 pm on Feb 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How many separate links will you be choosing from? If it's not a large list, you can do it with javascript - in fact there are a lot of cut and paste random link scripts out on the web which you could use or adapt.

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].

rlrouse

11:50 pm on Feb 16, 2003 (gmt 0)

10+ Year Member



Thanks Tedster. I'm looking at 25-30 links. What is your opinion about using JS to handle that many links? Too slow?

Thanks

tedster

12:28 am on Feb 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds OK to me. The list itself would probably be between 2kb -3kb. That would not require much extra download time at all, especially since it's text and benefits from native modem compression for most users.

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.

rlrouse

12:31 am on Feb 17, 2003 (gmt 0)

10+ Year Member



Thanks for the info!