Playing an audio file without spawning a new window ...

Discussion in 'Javascript' started by laredotornado, Jun 15, 2005.

  1. Hello, I want to play an audio file embedded on my page by clicking on
    an audio image and the page change to a new page. Is there a
    cross-browser Javascript way to do this? Right now the code I have
    is ...

    <title>Dictionary: homeostasis</title>
    <link href="liveink.css" type="text/css" rel="stylesheet"/>
    <div class="dictionary-area">
    <span class="dictionary-word">homeostasis</span>
    (<span class="dictionary-pos">Noun</span>)
    <div class="dictionary-defn">The maintenance of a constant internal
    state in a changing environment that is maintained by continually
    making adjustments to the internal and external environment.</div>
    <a href="homeostasis.mp3" target="new"><img src="audio.gif"
    <div class="dictionary-close-window"><a
    href="javascript:window.close()">Close Window</a></div>

    The inconvenience is right now a new window is spawned to play the
    audio., which contains the controller for playing the audio (complete
    with pause, stop, and play buttons). All my audio clips are less than
    3 seconds in length.. How can I play the audio file without launching
    the controller? I don't care if there's no way to stop/pause the audio
    once it's started.

    Thanks for your help, - Dave
    laredotornado, Jun 15, 2005
    1. Advertisements

  2. Try this:

    <title>Make some noize</title>

    <script type="text/javascript">

    var Sound = new Object(); = function Sound_play(src) {
    if (!src) return false;
    var elm;
    if (typeof document.all != "undefined") {
    elm = document.createElement("bgsound");
    elm.src = src;
    else {
    elm = document.createElement("object");
    this.elm = elm;
    return true;

    Sound.stop = function Sound_stop() {
    if (this.elm) {
    this.elm = null;


    onmouseout="Sound.stop()">Come over me</div>
    Daniel Kirsch, Jun 15, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.