I have written a function to copy text from a textarea but I need to have a particular code block executed if the user is using an apple mobile device.
I tried the following statement
if (navigator.userAgent.match(/iphone|ipod|ipad/)) {
// code
}
but it doesn't seem to work very well.
Do you have any suggestions?
/* Full code */
function copy(copyText) {
if (navigator.userAgent.match(/iphone|ipod|ipad/)) {
// handle iOS devices
copyText.contenteditable = true;
copyText.readonly = false;
var range = document.createRange();
range.selectNodeContents(input);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
input.setSelectionRange(0, 999999);
} else {
// other devices are easy
copyText.select();
}
document.execCommand("copy");
}