2010-02-18 50 views
1

我在站点上的菜单按钮上使用了以下脚本来实现onmouseover声音效果。Firefox中的Onmouseover声音

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


var aySound = new Array(); 

aySound[0] = "s.mp3"; 

document.write('<BGSOUND ID="auIEContainer">') 
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0; 
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0; 
ver4 = IE||NS? 1:0; 
onload=auPreload; 

function auPreload() { 
if (!ver4) return; 
if (NS) auEmb = new Layer(0,window); 
else { 
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>"; 
document.body.insertAdjacentHTML("BeforeEnd",Str); 
} 
var Str = ''; 
for (i=0;i<aySound.length;i++) 
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>" 
if (IE) auEmb.innerHTML = Str; 
else { 
auEmb.document.open(); 
auEmb.document.write(Str); 
auEmb.document.close(); 
} 
auCon = IE? document.all.auIEContainer:auEmb; 
auCon.control = auCtrl; 
} 
function auCtrl(whSound,play) { 
if (IE) this.src = play? aySound[whSound]:''; 
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()")) 
} 
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); } 
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); } 
//--> 
</script> 

这在IE中正常工作,但不是Firefox。

有没有人知道在没有使用闪存的情况下,在IE和Firefox中是否有相同的onmouseover音效?

感谢

回答

0

声音在您的网站唯一方法是使用Flash或任何的Facebook用于传入IM,但同样需要的Apple QuickTime播放。

0

有人知道如果在没有使用Flash的情况下IE和Firefox都有相同的onmouseover音效吗?

那么,你可以使用JavaScript库,它规范跨浏览器onmouseover行为。或者,如果你真的不想 - 在普通的'JavaScript'中应该是可能的,并且有很多黑客支持所有不同的浏览器。你的选择。

,张贴在gist 243946,这里是一个jQuery的片段做的正是你想要什么:

var $sound = $('<div id="sound" />').appendTo('body'); 
$('#special-links-that-play-annoying-sounds-when-hovered a').hover(function() { 
$sound.html('<embed src="foo.mp3" hidden="true" autostart="true" loop="false">'); 
}, function() { 
// We could empty the innerHTML of $sound here, but that would only slow things down. 
}); 

当然,这可以在普通的旧的JavaScript写成(无jQuery的)为好。