TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 17, 2024, 03:56:10 AM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 59
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 47
  • Total: 47

Play a sound on mouseover a block

Started by nokonium, May 15, 2006, 08:06:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

domineaux

I'm curious of anyone ever got this to work in the browsers...Opera, Netscape, IE and Firefox.

I'd like to put a sound file with a mouseover a block...jes' for fun.


Nokonium

This works in IE7, FF2 & Opera 9.1

Put it in a script block. I have attached the files I used.  >:D

<embed src="OLgraphics/fart4.wav"
width="0" height="0"
autostart="false" loop="false" name="mysound"
enablejavascript="true"/>
<script>
function playSound(soundname) {
var sound = eval("document." + soundname);

// make an effort to stop and rewind any playback
// already in progress so that the sound starts over.
// Otherwise this call has no effect when the sound
// is already in progress. You can remove these lines
// if you don't like this behavior.
try {
  sound.Stop();
  sound.Rewind();
} catch (e) {
  // A player that doesn't support
  // Stop and Rewind
}

try {
  // For RealPlayer-enabled browsers.
  // Some versions of RealPlayer do not
  // offer a Play() function and will
  // fail to play sound if we try to
  // call Play().
  sound.DoPlay();
} catch (e) {
  // If DoPlay doesn't work, call Play.
  // This works for all other audio
  // plug-ins.
  sound.Play();
}
}
</script>
<div align="center"><img src="OLgraphics/fartbutton3.gif" onclick="playSound('mysound')" /></div>