Check execCommand operation in firefox ('Copy' command)

3

I'm having trouble verifying that firefox ran the element.execCommand ('Copy', false, null) command.

This check is done correctly in Chrome (which does not allow) and in IE (which allows).

Could you please help me out?

The following part of the code follows:

editorDoc.body.focus();
editorDoc.execCommand ('SelectAll', false, null);
if( ! editorDoc.execCommand ('Copy', false, null) )
    alert('As opções de segurança do seu navegador impedem a cópia do conteúdo de maneira automática. Por favor, utilize [CTRL]+[C] em seu teclado.');

You can test the current operation here: link

Note : In firefox the text is selected, Chrome text is selected and the alert is issued, and not > IE 11 text is selected and copied to Clipboard.

    
asked by anonymous 13.03.2015 / 20:06

1 answer

2

Possibly the way you are using to check the execution of a command is not the most appropriate.

According to the HTML Editing APIs section, #

  

Some commands will be supported on a particular user agent, and   others do not. All commands defined in this specification must be   supported, except optionally the command copy , the command cut , and / or the paste . [...]

     

A command that does absolutely nothing on a user agent in   particular, such that execCommand () never has any It is made   and queryCommandEnabled () , queryCommandIndeterm () , queryCommandState () and queryCommandValue () each returns the same value all the time,   should not be supported.

     

In a particular user agent, all commands must be   consistently supported or not. [...] However, agents may   handle the same command as supported by some pages and some not, for example, if the command is only supported for certain   origins, for security reasons.

The recommendation is to use the queryCommandSupported method, which returns a Boolean that will indicate whether the command is supported or not, if supported, use the queryCommandEnabled "which will also return a Boolean value that indicates whether the command can be executed successfully using execCommand .

You can do something like this:

editorDoc = ...
if(editorDoc.queryCommandSupported('copy')){
    if(editorDoc.queryCommandEnabled('copy')){
        editorDoc.execCommand('copy', false, null);
    } // else {..} não está habilitado
} // else {..} não é suportado
    
22.03.2015 / 18:03