Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    dlk
    dlk is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Cookie to control background music

    Does someone have a javascript that would use a cookie to control backgound music so it only plays once during a browser session?

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    maybe

    <embed src="file.wav" autostart="true" hidden="true" loop="false">

    not js/cookie but it is what you asked for

  • #3
    dlk
    dlk is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Script for cookie controlled background music

    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •