Member
From: Sydney, Australia
Registered: 2004-10-23
Posts: 593
I've been thanked 0 times.
Offline
I have a small problem with a website I'm building. It has a short .wav file (musical piece on opening the Home Page that plays one loop) by customer request, I assure you!! 
Obviously, the piece plays again whenever you RETURN to the Home page from within the site. I've been asked if I can make it play ONLY on the initial opening. I've racked my brain and I can't think of a way...
Any suggestions??
Thanks
Wiz 
I cried because I had no shoes - until I saw a man who had no feet...
Member
From: York, England
Registered: 2005-11-04
Posts: 605
I've been thanked 11 times.
Offline
No suggestions, but heres a solution!!
Save this as musicfirstvisit.js ::
Code: javascript
// Start copying here for JavaScript section that plays music on first visit only!
var applicationName = navigator.appVersion;
var startLoc = applicationName.indexOf("(")+1;
var endLoc = applicationName.indexOf(";");
var machineName = applicationName.substring(startLoc, endLoc);
function getCookie(name) {
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin,end));
}
}
else {
return null;
}
}
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? " " : "; expires=" + expires.toGMTString());
}
function delCookie(name) {
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}
function embedSound(musicName) {
if (navigator.appName == "Netscape") {
document.write("<EMBED SRC=" + musicName + " WIDTH=1 HEIGHT=1 AUTOSTART=true HIDDEN=TRUE>");
}
else {
document.write("<BGSOUND SRC=" + musicName + ">");
}
}
function toPlayOrNot(musicName) {
if (getCookie("playMusic") == null) {
embedSound(musicName);
setCookie("playMusic", "visited", null);
}
}
// Stop copying for JavaScript section that plays music on first visit only.
Stick this in your head:
Code: javascript
<SCRIPT LANGUAGE="JavaScript" src="musicfirstvisit.js"></SCRIPT>
Paste this straight after your body tag::
Code: javascript
<SCRIPT LANGUAGE="JavaScript">
toPlayOrNot('MUSIC FILE')
</SCRIPT>
Chang MUSIC FILE to the name of your music file.
Upload everything to the same directory.
Should be right! 
Member
From: Sydney, Australia
Registered: 2004-10-23
Posts: 593
I've been thanked 0 times.
Offline
Thanks, Mate...
Your a lifesaver. I can come up smelling like a rose. (They already think I'm simply fantastic - Now I'll be 'Superhuman'...)
Thanks again
I cried because I had no shoes - until I saw a man who had no feet...
Member
From: York, England
Registered: 2005-11-04
Posts: 605
I've been thanked 11 times.
Offline
Your very welcome.
They already think I'm simply fantastic - Now I'll be 'Superhuman'
Clients are always in awe of web designers, or anyone who does anything computery.
Best thing is, you can totally bull them up by sucking your teeth n saying "ooo, but itll take time so itll cost ya" then spount words like variables, cache, http referers dont forget to say hypertext markup language instead of html and you can double the price!!!
its alot like being a car mechanic really!! 
Member
From: Sydney, Australia
Registered: 2004-10-23
Posts: 593
I've been thanked 0 times.
Offline
Thanks griffin.. but it's not working mate.
I'm sure it's all installed exactly as instructed but.... no go.
Have you used it yourself and had it working??
Thanks
Wiz 
I cried because I had no shoes - until I saw a man who had no feet...
Member
From: York, England
Registered: 2005-11-04
Posts: 605
I've been thanked 11 times.
Offline
No, never used it.
when I find stuff I think might be useful later on, i save the link
I got that from http://puma.wellesley.edu/~cs110/lectur … Music.html
view source n its all in there.
Member
From: Sydney, Australia
Registered: 2004-10-23
Posts: 593
I've been thanked 0 times.
Offline
Thanks mate. I'll have a look. At least I know there are scripts out there for this sort of thing.
I appreciate the lead...
Regards,
Wiz 
I cried because I had no shoes - until I saw a man who had no feet...
| Never |


