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

Trufa picture Trufa · Jan 26, 2011 · Viewed 11.9k times · Source

I've read the HTML5 spec for <command> and found the information on this element very vague.

I've tried it out and found that it is not working in Chrome (latest version) and it is working on Safari (even older ones), sorry no FF (don't shoot me please) - Mac only test.

I can't understand what is the use of this element or even if I'm using it correctly.

I thank you in advance for any clarification about it!

Answer

hallvors picture hallvors · Jan 26, 2011

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.