Javascript Firefox中的Onmouseover声音

Javascript Firefox中的Onmouseover声音,javascript,firefox,Javascript,Firefox,我使用下面的脚本在一个站点的菜单按钮上实现onmouseover声音效果 <script LANGUAGE="JavaScript"><!-- var aySound = new Array(); aySound[0] = "s.mp3"; document.write('<BGSOUND ID="auIEContainer">') IE = (navigator.appVersion.indexOf("MSIE")!=-1 && docum

我使用下面的脚本在一个站点的菜单按钮上实现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中不使用flash就能获得相同的onmouseover音效?


谢谢

在您的网站上播放声音的唯一方法是使用flash或Facebook用于接收IM的任何东西,但这也需要Apple Quicktime来播放

有人知道有没有办法在IE和Firefox中使用相同的
onmouseover
音效而不使用Flash

您可以使用JavaScript库来规范跨浏览器
onmouseover
行为。或者,如果你真的不想这样做的话——它应该可以用普通的ol'JavaScript实现,并通过大量的黑客攻击来支持所有不同的浏览器。你的选择

如中所述,这里有一个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.
});
var$sound=$('').appendTo('body');
$(“#当将鼠标悬停在a上时播放恼人声音的特殊链接”).hover(function(){
$sound.html(“”);
},函数(){
//我们可以在这里清空$sound的innerHTML,但这只会减慢速度。
});
当然,这也可以用简单的旧JavaScript编写(没有jQuery)