I have a grid that lists a huge amount of data. For each data row, I have a button that copies the specific row to the system clipboard.
The row button/link calls the javascript method in which I call the MVC controller method and pass the data to the textarea (styles applied to make it not visible).
Till a few days back it was working with all browsers (mainly needed to work in IE, Edge, Chrome, and Safari). Now the code is not working.
My javascript method goes this way:
function copytoclip(id) {
$.get('/controller/details', {
'commentid': id
}, function(data) {
var txt = document.getElementById('<%=txtcontrol.ClientID%>');
txt.value = data;
txt.textContent = data;
txt.select();
try {
//Below line returns false always in Chrome and Safari
var res = document.execCommand('copy', false, null);
if (res) {
alert('Copy to clipboard successful');
} else {
alert('Your browser doesn'
t support clipboard access ');}
}
catch (err) {
alert(err.message);
}
});
}
The result (res) is always false in Chrome and Safari. I tried to add the URL (http://servername:portname - runs in localhost; even it fails with the DNS in staging) to the Chrome's trusted site list for the clipboard access but in vein.
Can anyone give direction why the execCommand returns false always in Chrome and Safari?