We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Music Off and On --MouseOver,MouseOut

PerBoman
PerBoman asked
on
Medium Priority
621 Views
Last Modified: 2011-10-03
             Hi

Could anyone help me with this.
I want musik to be played when "onMouseOver" a link and the
musik should stop when "onMouseOut".
The code I did here below work but when I do "onMouseOut"
I start a where short empty midi-file , to stop the first one.
Couldn't I just stop the first one without start another,
and how?
And what does the parameter "mastersound" in embed tag do?
Without this it doesn't work at all?

Thank you in advanced / Pelle Sweden
(I want to give this question more points but thats all I have)
<HTML>
 <HEAD>
 <TITLE></TITLE>
 </HEAD>

 <SCRIPT LANGUAGE="JavaScript">
  function start() { document.on.play()}
  function stopp() { document.off.play()}
 </SCRIPT>

<BODY>
 <EMBED NAME="on"  SRC="musik2.mid" HIDDEN=true AUTOSTART=false mastersound></EMBED>
 <EMBED NAME="off" SRC="kort.mid"   HIDDEN=true AUTOSTART=false mastersound></EMBED>

 <A HREF="javascript:void(0)"
          onMouseover="start()"
          onMouseOut="stopp()">Music On/Off</A>

 </BODY>
 </HTML>
Comment
Watch Question

Okay try this:-

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function start()
{
document.the-name.play(false);
}

function stop()
{
document.the-name.play(true);
}
</SCRIPT>


<BODY>

<EMBED SRC="filename.wav" HIDDEN=TRUE AUTOSTART=FALSE NAME="the-name" MASTERSOUND>

<a href="your-link.html"
onMouseover="JavaScript:start();"
onMouseout="JavaScript:stop();">Start Music</A>

</BODY>

</HTML>

This simply changes the play property of the embedded sound when your mouse goes over the link.

Hope this helps
 

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I have tried this, it doesn't work on my computer.
The play function do the same regardless off the parameter
"true" or "false" . Why?
/Pelle Sweden
(Why do you have the parameter false on your function start,
 true seems more logic, but neither want work for me)
Hi Pelle,

Okay the script below works great for me.  It will only work in Netscape 3 or higher and will not work in MSIE 3 or 4, something to do with lack of support for the play() method.

The script uses two functions, one to start and one to stop the music.  The play() part of the start function has the switch false as this tells the music not to loop, if you wanted it to play repeatedly you would replace it with true.

The stop() is used in the second function to stop the music.

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
function start()
      {
      document.music.play(true);
      }

function stop()
      {
      document.music.stop();
      }
</SCRIPT>

</HEAD>



<BODY>

<EMBED SRC="midis/mission.mid" HIDDEN=TRUE AUTOSTART=FALSE NAME="music" MASTERSOUND>
<BR>
<a href="your-link.html"
onMouseover="start();"
onMouseout="stop();">Mouse Sensitive Music</A>

</BODY>

</HTML>

Hope this helps.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.