Flasher Archive
[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]
| Subject: | Re: Javascript/Flash Question |
| From: | Brian Medendorp |
| Date: | Tue, 18 Aug 1998 15:46:26 +0100 |
If you have each of the movies as separate files, you could write
a script that has an array of strings (containing the URL of the movies),
and have it randomly select a number, whence randomly selecting a
different movie. You could even use cookies to get it to loop in sequence
if you so desired. I wrote a similar script to display random ads on
multiple web-pages.
- [3rian :)
"Hi, I'm Chandler, Could I BE wearing anymore clothes?"
-Joey Tribbiani
On Mon, 17 Aug 1998 Crash1035
> I have multiple introduction movies for my site. Does anyone know of a way to
> randomly pick one every time a user comes to the site, so that they don't see
> the same moive over and over again?
> Thanks a lot,
> Hunter Powers
> WebAnchor
>
> ------------------------------------------------------------------------
> To UNSUBSCRIBE send: unsubscribe flasher in the body of an
> email to list-manager
> N.B. Email address must be the same as the one you used to subscribe.
> For info on digest mode send: info flasher to list-manager
>
//--Global Variables-----------------------------------------------------------
var max = 5;
var adNum;
var expdate = new Date();
var new_date = new Date();
//--Get Cookie Value-----------------------------------------------------------
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//--Get Cookie-----------------------------------------------------------------
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
//--Set Cookie-----------------------------------------------------------------
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
//--Delete Cookie--------------------------------------------------------------
function DeleteCookie(name) {
var exp = new Date();
FixCookieDate (exp);
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
if (cval != null)
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//--Create an Ad Object--------------------------------------------------------
function adObject() {
this.src = '';
this.href = '';
this.alt = '';
}
//--Cookie Information Handling------------------------------------------------
expdate.setTime(expdate.getTime()+(365.25*24*60*60*1000));
if (GetCookie("LAHSad") == null)
adNum = Math.round(Math.random() * (max-1)); //-or- adNum = 0;
else
if (GetCookie("LAHSad") >= max)
adNum = 0;
else
adNum = GetCookie("LAHSad");
adNum = Math.ceil(adNum);
adNum += 1;
SetCookie("LAHSad",adNum,expdate);
/* Note: For sequencial ad viewing use above code (Cookie Information Handling)
with adNum set to zero to start or adNum set to random to start
For random ad viewing use below code (Random Number Generator) */
//--Random Number Generator----------------------------------------------------
//adNum = Math.random();
//adNum = Math.round(adNum * (max-1))+1;
//--Array Information Handling-------------------------------------------------
adArray = new Array()
for (var i=1; i<=max; i++) {
adArray[i] = new adObject()
}
adArray[1].src="/ads/ad1.gif";
adArray[1].href="/ads/ad1.gif";
adArray[1].alt="Fake Ad #1";
adArray[2].src="/ads/ad2.gif";
adArray[2].href="/ads/ad2.gif";
adArray[2].alt="Fake Ad #2";
adArray[3].src="/ads/ad3.gif";
adArray[3].href="/ads/ad3.gif";
adArray[3].alt="Fake Ad #3";
adArray[4].src="/ads/ad4.gif";
adArray[4].href="/ads/ad4.gif";
adArray[4].alt="Fake Ad #4";
adArray[5].src="/ads/ad5.gif";
adArray[5].href="/ads/ad5.gif";
adArray[5].alt="Fake Ad #5";
//--Write the output-----------------------------------------------------------
document.writeln('<CENTER>');
document.writeln('<A HREF="'+adArray[adNum].href+'"><IMG SRC="'+adArray[adNum].src+'" ALT="'+adArray[adNum].alt+'" BORDER="1" WIDTH="468" HEIGHT="60"></A>');
document.writeln('</CENTER>');
Replies
Javascript/Flash Question, Crash1035
[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]

