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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing web content with respect to time of day 1

Status
Not open for further replies.

xoffox

Programmer
Joined
Oct 7, 2007
Messages
3
I have a photo oriented web site. I would like to be able to change the photos displayed several times a day based on the time of day. The photos are in 3 folders - flash/flash1/gallery. My thought is to include additional preloaded folders e.g.flasha/flash1a/gallerya. Then depending on the time of day either the photos in the first set of folders or the second set of folders would be displayed. At present I am only interested in changes with respect to the time of day and not the day of the week.

In truth I am not sure that javascript is the best way to do this?

Any guidance would be appreciated,

xof fox



 
After some thought I think the best approach is to try and rename the folders that reside on the server, assuming everything I want to use is already loaded. In order to reuse the folder images I think I would have to do a trip -

flash=flashb
flasha=flash
flashb=flasha

I really am not expecting any code. Just want to know if this can be done with javascript or is there a better way and if the logic to the renaming of the folders is the most effective way to do this.

Thanks,

xf
 
Hi

I would use some regular links to make to ensure the site will work without JavaScript. And will mark them with a distinct [tt]class[/tt] :
HTML:
<a href="/flash/" class="timesensitive">Flash</a>
<a href="/flash1/" class="timesensitive">Flash 1</a>
<a href="/gallery/" class="timesensitive">Gallery</a>
Then change the directory names in the links :
JavaScript:
[b]function[/b] setlinktime()
{
  [b]var[/b] now=[b]new[/b] Date()
  [b]var[/b] suffix=[i]''[/i]
  [b]if[/b] (now.getHours()>8) suffix=[i]'a'[/i]
  [b]else[/b] [b]if[/b] (now.getHours()>16) suffix=[i]'b'[/i]
  [b]if[/b] (suffix) {
    [b]var[/b] alist=document.getElementsByTagName([i]'a'[/i])
    [b]var[/b] alength=alist.length
    [b]for[/b] ([b]var[/b] i=0;i<alength;i++)
      [b]if[/b] (alist[i].className==[i]'timesensitive'[/i])
        alist[i].href=alist[i].href.replace(/(flash1?|gallery)/,[i]'$1'[/i]+suffix)
  }
}
window.onload=setlinktime
Sorry, but I am better in coding than in English...

Feherke.
 
Dr. F,

Thank you for your rapid response. I am not a javascript guru and it will take me awhile to go through the code.

1. It seems that this code goes to a different file based on the time. For example sometimes it would access gallery and at other times it would access gallery1. This will not work. What I have to do is actually change the name of the file that is already on the server. The reason is that at least for the gallery file there are numerous calls to the file from other parts of the program. Therefore I have to change the name of the file gallery to something like gallery2, then change the name of the file gallery1 to gallery, and then change the name of gallery 2 to gallery 1. Then when the rest of the program accesses gallery it will get the new photographs that were once in gallery 1.

2. I am still not sure that javascript is the best way to change file names that already reside on the server?

Again thanks,

xf
 
Code:
I have a photo oriented web site
How many images are you actually dealing with?
What other image manipulation are you doing within the site?
If you do a lot of variation in displayed images, consider a database approach to your file selection, it makes even complex selection easy to achieve and the location dir of the images is no longer critical. If you only have a small number of images, the same information could be stored in a flat file.

Keith
 
Hi

Oops. I understood that you have the alternatives and only want to direct the visitor to one or another.

Now seems you want to implement kind of image-theft protection. But probably I am wrong again... Anyway, I do not recommend to physically rename the files or directories, because that will fool the search engines.

And unless you have some server-side JavaScript, no, JavaScript is not suitable for such renaming.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top