在 FF(FireFox)和 NS(Netscape)中不能像 IE 中那样直接使用 event 对象,请先阅读:Netscape 中使用 event 对象。
除此之外,它们对 button 的解释也不同。
在 IE 中,event.button 值为:左键-1,右键-2,中键(滚轮按下)-4。
在 FF 和 NS 中,event.button 值为:左键-0,右键-2,中键(滚轮按下)-1。
//不同的浏览器有不同的鼠标按钮值
//此函数将鼠标事件的按钮值统一
//按下鼠标左键,返回 l
//按下鼠标右键,返回 r
//按下鼠标中键(滚轮),返回 m
function TranslateButton(event)
{
if (window.navigator.appName.indexOf("Microsoft") >= 0)
{
//IE5.0、IE6.0 的 appName 均为:Microsoft Internet Explorer
//腾讯TT、傲游等使用 IE 内核的浏览器,其 appName 也为:Microsoft Internet Explorer
//这里不能使用 document.all 来判断,因为 Opera 也具有 document.all 属性,但其鼠标按钮值却和 FireFox 是一类的。
if (event.button == 1)
{
return "l";
}
else if (event.button == 2)
{
return "r";
}
else if (event.button == 4)
{
return "m";
}
}
else
{
if (event.button == 0)
{
return "l";
}
else if (event.button == 2)
{
return "r";
}
else if (event.button == 1)
{
return "m";
}
}
return "";
}