我的鼠标侧面有两个按钮,默认行为是“后退”和“前进”。
我想知道的是是否可以在JavaScript中检测这些鼠标按钮的单击事件,或者它们是否类似于键盘上的“播放”,“音量增加”和“无线开关”按钮等“特殊”按钮。
我的鼠标侧面有两个按钮,默认行为是“后退”和“前进”。
我想知道的是是否可以在JavaScript中检测这些鼠标按钮的单击事件,或者它们是否类似于键盘上的“播放”,“音量增加”和“无线开关”按钮等“特殊”按钮。
我不知道具体的鼠标事件。
但是,你可以通过检查mousedown
事件的event
对象来轻松找到。
var text = typeof document.body.textContent != "undefined" ? "textContent" : "innerText";
window.onmousedown = function(e){
//Inspect the `e` object, for example using a for(var i in e) loop, or:
//console.log(e);
var s = [];
for(var i in e){
try{
if(e[i] !== null){
if(i.toUpperCase() == i) continue; //Ignore constants
if(typeof e[i] == "function") continue; //Ignore functions
if(e[i].parentNode) continue; //Ignore elements
if(e[i] === window) continue; //Ignore Window
}
s.push(i + " =\t\t" + e[i]);
}catch(err){s.push(i + " \tERROR reading property.")}
}
e.preventDefault();
s = s.join("\n") + "\n\n";
document.body[text] = s + document.body[text];
}
//Double-click to wipe contents
window.ondblclick = function(){
document.body[text] = "";
}
return false
或 e.preventDefault()
,因为鼠标似乎告诉浏览器要切换页面。如果浏览器没有拦截,那么你就知道它不可用了。 - Dominic Barnesevent.which
在所有主要浏览器中都得到支持(除了IE 8及以下版本),这让我修复了代码中其他地方的一些问题。谢谢! - Niet the Dark Absol