...

View Full Version : Cookie to control background music



dlk
02-27-2003, 03:33 PM
Does someone have a javascript that would use a cookie to control backgound music so it only plays once during a browser session?

bfsog
02-27-2003, 03:56 PM
<embed src="file.wav" autostart="true" hidden="true" loop="false">

not js/cookie but it is what you asked for

dlk
02-27-2003, 06:58 PM
I'm answering my own question!

This script will play a background sound only once during a browser session.

Place in the <head> section:

<script>

function playmusic(){
document.write('<embed src="fun.wav" autostart="true" hidden="true" loop="false"></embed>');
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function playornot(){
if (get_cookie('playedonce')==''){
playmusic()
document.cookie="playedonce=yes"
}
}

playornot()
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum