Hi guys,
i tried the following methods it worked for desktop. But none seems to work for IOS. Is there some setting i need to do?
https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios
window.copyStringToClipboard = function copyStringToClipboard(textToCopy) {
var textArea;
function isOS() {
//can use a better detection logic here
return navigator.userAgent.match(/ipad|iphone/i);
}
function createTextArea(text) {
textArea = document.createElement('textArea');
textArea.readOnly = false;
textArea.contentEditable = true;
textArea.value = text;
document.body.appendChild(textArea);
}
function selectText() {
var range, selection;
if (isOS()) {
range = document.createRange();
range.selectNodeContents(textArea);
selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
textArea.setSelectionRange(0, 999999);
} else {
textArea.select();
}
}
function copyTo() {
document.execCommand('copy');
document.body.removeChild(textArea);
}
console.log("String: " +textToCopy);
createTextArea(textToCopy);
selectText();
copyTo();
}