Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotating SSI's with Javascript

Status
Not open for further replies.

egims

Technical User
Jun 5, 2001
96
US
I just thought I'd ask. I'm a Javascript novist at best and can't figure out how to do what I think is a simple thing with Javascript.

The best way to describe what I'm trying to do is like this:

Lets say you took a web page and divided it up into 4 equal squares. Then had the HTML content for each square inserted into the page via a server side include.

Here is what I need to do. Each time the page is visited I want the page content for each square (the server side include) to rotate clockwise. That's it. So the SSI that placed content into the top left now goes into the top right. The content that was in the top right now moves to the bottom right, and so on for all 4 squares.If anyone can help me with the code to do this I would appreciate it greatly.
 
Hi

Just to show you the amount of JavaScript needed when using SSI to include content :

[tt][blue][small][ignore][off-topic][/ignore][/small][/blue][/tt]
Supposing the four files to include are named one.shtml, two.shtml, three.shtml, four.shtml :
Code:
[red]<!DOCTYPE[/red] [maroon]HTML[/maroon] [maroon]PUBLIC[/maroon] [green][i]"-//W3C//DTD HTML 4.01//EN"[/i][/green] [green][i]"[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd"[/URL][/i][/green][red]>[/red]
[b]<html[/b] [maroon]lang[/maroon][teal]=[/teal][green][i]"en"[/i][/green][b]>[/b]

[gray]<!--#set var="list" value="one two three four one" -->[/gray]
[gray]<!--#if expr="$HTTP_COOKIE = /topleft=(\\w+)/" -->[/gray]
  [gray]<!--#if expr="$list = /$1 (\\w+)/" --><!--#endif -->[/gray]
  [gray]<!--#set var="topleft" value="$1" -->[/gray]
[gray]<!--#else -->[/gray]
  [gray]<!--#set var="topleft" value="one" -->[/gray]
[gray]<!--#endif -->[/gray]

[b]<head>[/b]
[b]<meta[/b] [maroon]http-equiv[/maroon][teal]=[/teal][green][i]"content-type"[/i][/green] [maroon]content[/maroon][teal]=[/teal][green][i]"text/html; charset=iso-8859-1"[/i][/green][b]>[/b]
[b]<title>[/b]Rotate[b]</title>[/b]
[b]<meta[/b] [maroon]http-equiv[/maroon][teal]=[/teal][green][i]"set-cookie"[/i][/green] [maroon]content[/maroon][teal]=[/teal][green][i]"topleft=<!--#echo var="[/i][/green][maroon]topleft[/maroon][green][i]" -->; expires=01/01/2011 00:00:00 AM"[/i][/green][b]>[/b]
[b]</head>[/b]

[b]<body>[/b]

[b]<div[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"topleft"[/i][/green][b]>[/b]
[gray]<!--#include file="$topleft.shtml" -->[/gray]
[b]</div>[/b]

[b]<div[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"topright"[/i][/green][b]>[/b]
[gray]<!--#if expr="$list = /$topleft (\\w+)/" --><!--#endif -->[/gray]
[gray]<!--#include file="$1.shtml" -->[/gray]
[b]</div>[/b]

[b]<div[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"bottomleft"[/i][/green][b]>[/b]
[gray]<!--#if expr="$list = /$1 (\\w+)/" --><!--#endif -->[/gray]
[gray]<!--#include file="$1.shtml" -->[/gray]
[b]</div>[/b]

[b]<div[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"bottomright"[/i][/green][b]>[/b]
[gray]<!--#if expr="$list = /$1 (\\w+)/" --><!--#endif -->[/gray]
[gray]<!--#include file="$1.shtml" -->[/gray]
[b]</div>[/b]

[b]</body>[/b]

[b]</html>[/b]
Tested with Apache.
[tt][blue][small][ignore][/off-topic][/ignore][/small][/blue][/tt]

Next time please do some research before asking.

Feherke.
 
Hi feherke. Thank you for your help.

By "novist at best" I meant that I strictly have a minor ability to pick at existing code. I can not write either javascript or PHP from scratch. By "research", I spent no less than 10 solid hours for two days searching the internet for some script that would do this, and came up dry. Very frustrating.

Your code above looks great. The only problem is that I need the includes to rotate as you designed, but in a more permanent way. What I mean is that whatever the position of the includes rotated to, I need them to appear that way when the next viewer comes along. A continuing permanent rotation. Not to restart in the same position when the next viewer comes along, thus the initial position would never change without a refresh. Am I making any sense?

If you know how to cause that I would really be very thankful.

 
Hi

You mean the included pieces should be rotated continuously for all visitors :

[red]A[/red] [green]B[/green] [blue]C[/blue] [purple]D[/purple] - visitor 1, request 1
[purple]D[/purple] [red]A[/red] [green]B[/green] [blue]C[/blue] - visitor 1, request 2
[blue]C[/blue] [purple]D[/purple] [red]A[/red] [green]B[/green] - visitor 2, request 1
[green]B[/green] [blue]C[/blue] [purple]D[/purple] [red]A[/red] - visitor 1, request 3

In that case both SSI and JavaScript are dead end, because you will need to store the last position server-side.

Feherke.
 
Hello again.

Yes, you have it exactly.

That's a bummer, for sure. Do you know it this solution can be done in PHP? Do you know of any scripts that can do this?

I have seen 1000's of scripts for rotating banners, but what I need is a script that can rotate code. I found one or two that could dynamically rotate code, but only display one piece of code at a time, and always "random". Don't need random.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top