Clipboard in JS

Flash

Librairie

exec Command

Text

Text

Text

Chrome

Safari

Firefox

IE

var urlField = document.querySelector('#url_field');
   
// create a Range object
var range = document.createRange();  

// set the Node to select the "range"
range.selectNode(urlField);

// add the Range to the set of window selections
window.getSelection().addRange(range);
   
// execute 'copy'
document.execCommand('copy');

Librairie

API

caniuse.com

 Specification

Specification

//CopyEvent
var copyEvent = new ClipboardEvent('copy', 
    { 
        dataType: 'text/plain', 
        data: 'Data to be copied' 
    }
);

document.dispatchEvent(copyEvent);

//PasteEvent
var pasteEvent = new ClipboardEvent('paste', 
    {
        dataType: 'text/plain', 
        data: 'My string' 
    }
);
document.dispatchEvent(pasteEvent);

La meilleur Solution ? 

Hell 's clipboard

By nafresne

Hell 's clipboard

  • 591