Javascript 右键单击Firefox检测
在开始之前,我并不是想阻止用户右键单击。这是为了在html5画布上进行右键单击检测 因此,目前我所拥有的是:Javascript 右键单击Firefox检测,javascript,Javascript,在开始之前,我并不是想阻止用户右键单击。这是为了在html5画布上进行右键单击检测 因此,目前我所拥有的是: function init() { var canvas = document.getElementById('canvasID');\ if (canvas.getContext) { ctx = canvas.getContext('2d'); ctx.font = '10px sans-serif'; ctx.canvas.onmoused
function init() {
var canvas = document.getElementById('canvasID');\
if (canvas.getContext) {
ctx = canvas.getContext('2d');
ctx.font = '10px sans-serif';
ctx.canvas.onmousedown=ctx.canvas.onclick=onMousePressed;
ctx.canvas.onmouseup=ctx.canvas.onmouseout=onMouseReleased;
ctx.canvas.onmousemove = onMouseMove;
}
}
而且:
移动鼠标的功能(e){
如果(鼠标向下){
单击2=convertCoordsToTileCoords({
x:e.offsetX | | e.layerX-this.style.left,
y:e.offsetY | | e.layerY-this.style.top
});
var右键单击;
如果(!e)e=window.event;
如果(e.which)右击=(e.which==3);
如果(e.button)右击=(e.button==2),则为else;
…等其中变量“rightclick”是布尔值,如果用户右键单击,则结果为true 这适用于哪些浏览器: 铬 歌剧,不,因为他们的鼠标手势和其他东西。 不,是因为帆布。 但我不明白为什么它不能在Firefox上运行 像往常一样,如果有更好、更有效的方法来解决这个问题,我们将不胜感激 -大副
Edit1:提供了更多的代码。如果您不介意使用jQuery,则存在一个更简单的解决方案。在Firefox 3.6.4/Mac中测试这一点的效果与预期一致:
document.onclick = function(e) {
var rightclick;
if (!e) e = window.event;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
alter(rightclick);
}
可能您没有正确附加单击处理程序?您可能应该接受一个答案。。。
document.onclick = function(e) {
var rightclick;
if (!e) e = window.event;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
alter(rightclick);
}