alex321
2018-01-17 09:07:26 +08:00
纯手写 //////
var sbox = document.createElement('input');
sbox.setAttribute('id', 'el');
sbox.setAttribute('value', value);
document.body.appendChild(sbox);
var el = document.getElementById('el');
// check is iOS or not
if(navigator.userAgent.match(/ipad|iphone/i)) {
var editable = el.contentEditable;
var readOnly = el.readOnly;
el.contentEditable = true;
el.readOnly = false;
var range = document.createRange();
range.selectNodeContents(el);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
el.setSelectionRange(0, 999999);
el.contentEditable = editable;
el.readOnly = readOnly;
} else {
el.select();
}
//console.log(window.getSelection().toString());
document.execCommand('Copy', false, null);