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

L

laredotornado

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 ...

<html>
<head>
<title>Dictionary: homeostasis</title>
<link href="liveink.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div class="dictionary-area">
<span class="dictionary-word">homeostasis</span>
(<span class="dictionary-pos">Noun</span>)
<br/>
<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"
border="0"></a>
<div class="dictionary-close-window"><a
href="javascript:window.close()">Close Window</a></div>
</div>
</body>
</html>

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
 
D

Daniel Kirsch

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.

Try this:

<html>
<head>
<title>Make some noize</title>

<script type="text/javascript">
<!--

var Sound = new Object();
Sound.play = function Sound_play(src) {
if (!src) return false;
this.stop();
var elm;
if (typeof document.all != "undefined") {
elm = document.createElement("bgsound");
elm.src = src;
}
else {
elm = document.createElement("object");
elm.setAttribute("data",src);
elm.setAttribute("type","audio/x-wav");
elm.setAttribute("controller","true");
}
document.body.appendChild(elm);
this.elm = elm;
return true;
};

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

//-->
</script>
</head>

<body>
<div
onmouseover="Sound.play('klatschn.wav')"
onmouseout="Sound.stop()">Come over me</div>
</body>
</html>
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top