• Hi, all.

    I am making a light-hearted comedy/musical site. I want a random sound file to play every time a new page or single post page or opens up (like Homer Simpson saying D’ope, or More Cowbell, etc.).

    How could I do this?

    I know how to make one play:

    if (navigator.appName == "Microsoft Internet Explorer") {
    document.write('<bgsound src="http://startupselling.com/natestest/wp-content/uploads/igottahavemorecowbellbaby.wav" loop="false">');
    }
    else {
    document.write('<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="MediaPlayer" src="http://startupselling.com/natestest/wp-content/uploads/igottahavemorecowbellbaby.wav" autostart="true" showstatusbar="0" showcontrols="0" showdisplay="0" volume="1" height="1" width="1" loop="false"><br />');
    }

    Then paste this into the page:

    <script type="text/javascript" src="http://startupselling.com/natestest/wp-content/uploads/morecowbell.js"></script>
    <script type="text/javascript">
    <!--
    updatepage();
    //--></script>

    But I really know nothing about JavaScript arrays, which I’m pretty sure is what I need here.

    It might also be good to know how to use a custom field to do it, that way the sound bites wouldn’t need to be random, I could put a sound bite on a page that is related to that page.

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter geezerd

    (@geezerd)

    Anyone have any ideas here? Thanks.

    This may be totally off-base because I do not know JavaScript. However, you might be able to use the technique described in this article.

    Can you use PHP to select the song and then generate the JavaScript to play it, embedding the song as a PHP variable?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Script to play random background sound on each page opening?’ is closed to new replies.