|
|
|
c0ldfyr3
Andrew J Gurklies |
Posted:
Sat May 17, 2008 4:17 am |
|
|
|
PRO BRONZE
Joined: 02 May 2004
Posts: 3067
Location: 127.0.0.1
|
here is how to do it.... I have questions though..
| Code: |
function adArray() {
for (i=0; i*2<adArray.arguments.length; i++) {
this[i] = new Object();
this[i].src = adArray.arguments[i*2];
this[i].href = adArray.arguments[i*2+1];
}
this.length = i;
}
function getAdNum() {
dat = new Date();
dat = (dat.getTime()+"").charAt(8);
if (dat.length == 1)
ad_num = dat%ads.length;
else
ad_num = 0;
return ad_num;
}
var ads = new adArray(
"/artists/portfolios/brandon/IMG_1.jpg","http://www.provocativetattoo.com",
"/artists/portfolios/brandon/IMG_2.jpg","http://www.provocativetattoo.com");
var ad_num = getAdNum();
document.write('<A HREF="'+ads[ad_num].href+'"><IMG SRC="'+ads[ad_num].src+'" WIDTH="300" HEIGHT="300"></A>');
link_num = document.links.length-1;
function rotateSponsor() {
if (document.images) {
ad_num = (ad_num+1)%ads.length;
document.js_ad.src = ads[ad_num].src;
document.links[link_num].href = ads[ad_num].href;
setTimeout("rotateSponsor()",604800000);
}
}
setTimeout("rotateSponsor()",604800000);
|
okay right at the end the line
| Code: |
setTimeout("rotateSponsor()",604800000);
|
should rotate the image every week. I figured that if 5000 = 5 seconds, then 604800000 = 1 week...
except it does not seem to be working.
i need the image to rotate every week.
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
jbullard
Jason Bullard |
Posted:
Sat May 17, 2008 5:36 am |
|
|
|
VP - Software
Joined: 06 Jun 2004
Posts: 3304
Location: Utah
|
You need to set a cookie variable otherwise with each page refresh it will cause it to set a new date/time for the week. This script would only work if the page was opened once and left opened for at least 1 week.
I don't have an example right now but I can work one up tomorrow. 
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
c0ldfyr3
Andrew J Gurklies |
Posted:
Sun May 18, 2008 3:29 pm |
|
|
|
PRO BRONZE
Joined: 02 May 2004
Posts: 3067
Location: 127.0.0.1
|
|
awesome... cuz i have no idea how to write a valid cookie....
i have seen a few examples, i am just not so good at it.
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
jbullard
Jason Bullard |
Posted:
Wed May 21, 2008 10:54 pm |
|
|
|
VP - Software
Joined: 06 Jun 2004
Posts: 3304
Location: Utah
|
|
|
Back to top
|
|
|
|
c0ldfyr3
Andrew J Gurklies |
Posted:
Thu May 22, 2008 12:51 am |
|
|
|
PRO BRONZE
Joined: 02 May 2004
Posts: 3067
Location: 127.0.0.1
|
i like that script, however i think that cookies would be best, or something on the server side. As i have 90 images and counting to rotate. the owner wants the artists portfolios accessed and at random an image to be selected and posted each week.
with that code i would have to add some more stuff in... IE folder dating and it would need to select the year and month that it is, then randomize the images by what was uploaded that week. since they will only be updating the images about once every three moths, this method would not work.
AWESOME find though 
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
jbullard
Jason Bullard |
Posted:
Thu May 22, 2008 12:20 pm |
|
|
|
VP - Software
Joined: 06 Jun 2004
Posts: 3304
Location: Utah
|
|
Do you have other scripting languages availables like PHP?
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
poisonbl
Joshua M. Murphy |
Posted:
Thu May 22, 2008 12:45 pm |
|
|
|
PRO Level 15
Joined: 15 Nov 2004
Posts: 1041
Location: WVU -- Morgantown, WV. -- USA (TZ: -5 hrs GMT, -4 DST)
|
|
Cookies really isn't likely what you want, they're *very* dependent on the user side, and a lot of users anymore kill cookies by default, either completely or at browser close (meaning the cookie would be lost within your week timeframe). Also, with cookies, the image shown to a given user would differ from one to the next, so any user to user interaction about it would be rather useless, as they could be talking to each other about any of the images and never realize it (people assume consistency).
You could, though, use some server side code (I could write up something to do the job in php fairly easily) to detect what day/week it is and pull up another image. The work of it would all be transparent to the user, who'd see it as though you simply replaced the old weekly feature with the new. If you have anything other than php (but still server side), I'm rather helpless, but may be able to point you in the right direction.
As for doing it only with JS, my best idea is just to set up a pre-written array of image filenames, and have it pull the user's date, subtract an initial date (converted to seconds or days from some given epoch), convert that to weeks from the initial date, and then use that as your array index to pick what image you should be using. Getting it truly "random" but consistent across all users per week ... might be possible, but the how (without server side coding) isn't coming to me. Oh, and the above *is* limited in consistency by the user's date/time being accurate, but that's their fault, at that point, not yours.
EDIT: If you can't do PHP/ASP/etc., but you can set scheduled tasks (or cron jobs) on the server ... you can have a text written weekly with the new random image filename, then have *that* pulled by javascript and written into the document on load ... but hosting that offers you that much control almost always offers some sort of server side coding.
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
c0ldfyr3
Andrew J Gurklies |
Posted:
Thu May 22, 2008 8:09 pm |
|
|
|
PRO BRONZE
Joined: 02 May 2004
Posts: 3067
Location: 127.0.0.1
|
|
i can do php, and that was my original preferred code.
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
c0ldfyr3
Andrew J Gurklies |
Posted:
Mon Jun 02, 2008 8:16 pm |
|
|
|
PRO BRONZE
Joined: 02 May 2004
Posts: 3067
Location: 127.0.0.1
|
|
can anyone help with a cookie and how to implement it into the code?
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
jbullard
Jason Bullard |
Posted:
Mon Jun 02, 2008 11:33 pm |
|
|
|
VP - Software
Joined: 06 Jun 2004
Posts: 3304
Location: Utah
|
Sorry man, I have been so busy lately with other programming stuff. But, I would suggest using PHP as it is a much better solution for what you want. I will see if I can't create a script for you. May take a week but I will try and get something for you. At least something to start with. 
|
|
|
|
|
|
|
|
Back to top
|
|
|
|
|
Back to top |
|
|
|
|
|