What exactly is the HTML5 <command> tag and what is the browser support

元气小坏坏 提交于 2019-11-28 10:45:27

It works on Firefox 3.6.13 from Windows by the way.

The command element is meant to encapsulate something that you can do. It can be rendered within a menu (since a menu presents items you can invoke).

The idea

It provides an abstraction layer between UI and commands, so that you can make multiple UI elements refer to the same command. This gives you the flexibility of having one command element, rendered in a menu, that is also invoked via a URL in the middle of the page as well as a button at the bottom of the page. Disabling the command disables all access paths (url/button/menu) to the action behind the command.

Where we are at - as of 26 Jan 2010

There is currently very scarce information as to how linking it to multiple elements will actually work (since browsers have only just started implementing it!) but that is one of its intentions.

At the present moment, the only documented usage is to provide a semantically unique tag to specify (without using <input> or <button> elements) that it is a command within a <menu>, thereby allowing "real" menu rendering by the browser (when implemented).

The <command> element is meant to be an abstraction to let you refer to the same "command" from multiple menu entries or buttons. AFAIK the idea is something like

<command id="doThat" onclick="doThat()"></command>
<input type="button" command="doThat" value="click me to do that">
<menu command="doThat">This does that too</menu>

Then, if you want to indicate that the user can not do that in the context, you could do

document.getElementById('doThat').disabled=true;

and both the button and the menu entry would become disabled. Or you could assign a shortcut key to the command element, and either menu and button would respond to the shortcut. Things like that.

I'm not sure but I think this part of HTML5 is unfinished and likely will be removed before HTML5 is released as a final specification? As-is, it is indeed unclear how it is intended to work.

command has been removed in favor of menuitem. Further info:

  • http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-December/038472.html
  • http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#the-menu-element

User-agents define the <a /> tag as interactive, but this element was only designed to make an hypertext reference without any idea of click.

This user-agent behavior became a standard, which is not the same with the longdesc attribute of the <img /> tag.

Because HTML was designed to structure information and contents, not to make interactions, the new version of HTML (5) tries to "palliate" this lack and introduces the <command /> tag to have interactions on HTML non-informative contents as "read more" anchors in example.

Note that "A command can be explicitly part of a context menu or toolbar" should also say that the <command /> can be used in another context and does not require <form /> tag instead of <input /> or <button />.

Thank you to Spontifixus & Daniel Kutik for correcting this answer

The lists.whatwg.org link went dead - the related discussion can be found on:

http://lists.w3.org/Archives/Public/public-whatwg-archive/2012Dec/0264.html

Subject "[whatwg] and friends", From: Ian Hickson , Date: Sat, 29 Dec 2012 01:23:20 +0000 (UTC)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!