Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change image and play sound on mouseover

Status
Not open for further replies.

malibu65k

Programmer
Sep 27, 2004
131
US
Hi All,

I have this code to change an image on mouseover and play a sound file. If I write the code separate they work fine but I can't get the sound to work when I have them together. Any ideas why it doesn't play when they are together? The sound plays if I set autostart to true.

Code...

<html>
<head>
<script LANGUAGE="JavaScript">
<!--

if (document.images) {

home = new Image();
home.src = "vMocha.jpg";
home2 = new Image();
home2.src = "vLatte.jpg";

}
function OnImage(name) {
if (document.images) {
fullname = eval(name + "2");
document[name].src = fullname.src;
}}
function OffImage(name) {
if (document.images) {
fullname = eval(name);
if (fullname.complete) {
document[name].src = fullname.src;

}}}
var agt=navigator.userAgent.toLowerCase();
var is_major=parseInt(navigator.appVersion);
var is_minor=parseFloat(navigator.appVersion);
var is_nav=((agt.indexOf('mozilla')!=-1)&&(agt.indexOf('spoofer')==-1)&&(agt.indexOf('compatible')==-1)&&(agt.indexOf('opera')==-1)&&(agt.indexOf('webtv')==-1));
var is_ie=(agt.indexOf('msie')!=-1);
if(is_ie){
var agt_ie=agt.substring(agt.indexOf('msie')+5); is_major=parseInt(agt_ie); is_minor=parseFloat(agt_ie);
}
var is_dom2=(document.getElementById);
function jsStop( o )
{
if(is_ie&&is_major>=4&&eval('document.'+o)){var e=eval('document.'+o);
if(e.src&&e.src!=''&&e.ReadyState&&e.ReadyState>=4){e.stop();
}}
else
{
if(is_nav&&is_major>=3&&(is_major<4||eval('document.'+o))){eval('document.'+o+'.stop()');
}}}
function jsPlay( o )
{
if(is_ie&&is_major>=4&&eval('document.'+o))
{
var e=eval('document.'+o);
if(e.src&&e.src!=''&&e.ReadyState&&e.ReadyState>=4)
{
if (is_major>=5){e.play();
}
else
{
e.run();
}}}
else{
if(is_nav&&is_major>=3&&(is_major<4||eval('document.'+o))){eval('document.'+o+'.play(false)');
}}}
//-->
</script>

</head>

<body>

<a href=" ONMOUSEOVER="OnImage('home');javascript:jsPlay('wav1');return true;" ONMOUSEOUT="OffImage('home');javascript:jsStop('wav1');return true;"><img name="home" src="vMocha.jpg" border="0"></a>

<EMBED name="wav1" src="harley.wav" autostart="false" mastersound hidden="true" volume=100 width=0 height=0>


</body>


</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top