これにHTML5クリップボードAPIを使用します。唯一の近代的なブラウザでは動作しますClipboard browser support
function copyText() {
var tmpElem = document.createElement('div'),
selection;
tmpElem.textContent = 'Your text want to copy';
document.body.appendChild(tmpElem);
if (document.selection) {
selection = document.body.createTextRange();
selection.moveToElementText(tmpElem);
selection.select();
} else if (window.getSelection) {
selection = document.createRange();
selection.selectNode(tmpElem);
window.getSelection().removeAllRanges();
window.getSelection().addRange(selection);
}
document.execCommand('copy');
tmpElem.remove();
}
<button onclick='copyText()'>Copy on clipboard</button>