setClipboardText = function(event) {
var htmlData, node, textData;
event.cancelable = true;
event.preventDefault(); //add this code will make iOS paste null
node = document.createElement('div');
node.appendChild(window.getSelection().getRangeAt(0).cloneContents());
htmlData = '<div>Some copyright' + node.innerHTML + '</div>';
textData = 'Some copyright' + window.getSelection().getRangeAt(0);
event.clipboardData.setData('text/html', htmlData);
event.clipboardData.setData('text/plain', textData);
};
copyrightRange = document.getElementById('content-copyright');
copyrightRange.addEventListener('copy', function(e) {
setClipboardText(e);
The code above will work on the pc browsers, but on the mobile browsers, it doesn't work. I have test the problem is event.preventDefault();
.But without this, my function will not make sense.Can somebody help me?