Text
Text
Text
codepen / execCommands supported in your browser
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');
//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);