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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,021
  • Total Topics: 21,332
  • Online today: 496
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 301
  • Total: 302
  • lurkalot

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>

This website is proudly hosted on Crocweb Cloud Website Hosting.