GlobalEventHandlers.onauxclick

这篇翻译不完整。请帮忙从英语翻译这篇文章

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

 

The onauxclick property is an EventHandler called when an auxclick event is sent, indicating that a non-primary button has been pressed on an input device (e.g. a middle mouse button).

This property is implemented as part of a plan to improve compatibility between browsers with regards to button behaviours — event behaviour is being updated so that click only fires for primary button clicks (e.g. left mouse button). Developers can then use auxclick to provide explicit behaviour for non-primary button clicks. Previous to this, click generally fired for clicks on all input device buttons, and browser behaviour was somewhat inconsistent.

Syntax

element.onauxclick = functionRef(e);

The event handler function is a MouseEvent object. Apart from the button(s) the event is fired on, the behaviour is exactly the same.

Example

In this example we define two event handler functions — onclick and onauxclick. The former changes the color of the button background, while the latter changes the button foreground (text) color. You can see the two functions in action by trying the demo out with a multi-button mouse (see it live on GitHub; also see the source code).

var button = document.querySelector('button');
var html = document.querySelector('html');

function random(number) {
  return Math.floor(Math.random() * number);
}

button.onclick = function() {
  var rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
  button.style.backgroundColor = rndCol;
};

button.onauxclick = function() {
  var rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
  button.style.color = rndCol;
}

Note: If you are using a three-button mouse, you'll notice that the onauxclick handler is run when either of the non-left mouse buttons are clicked.

Notes

The click event is raised when the user clicks on an element. The click event will occur after the mousedown and mouseup events.

Only one click handler can be assigned to an object at a time with this property. You may be inclined to use the EventTarget.addEventListener() method instead, since it is more flexible and part of the DOM Events specification.

Specification

onauxclick is not part of any official specification yet; the definition can be found in the auxclick Draft Community Group Report.

Browser Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support ? 53 (53) 未实现 ? 未实现
Feature Android Android Webview Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未实现 ? ? 53 (53) ? 未实现 未实现

文档标签和贡献者

标签: 
 此页面的贡献者: maicss
 最后编辑者: maicss,