Hello Guys,
I am currently using plain javascript code inside meteor.call callback to copy text, but got no success.
Here is my code sample-
var field = document.getElementById('someId');
field.focus();
field.setSelectionRange(0, field.value.length);
var success = document.execCommand("copy");
console.log("Copy success >>>>>>>", success)
It always console false.
So I have query, Is copy text functionality not supported inside meteor.call callback ?
If it is supported, Please help me for this issue ?
I’ve confirmed this works as expected, so I suspect the issue is with your code - specifically where you are running this, as the DOM may not be ready.
I just tried it and for me it fails as well.
I tested it by calling Meteor.call in the browser console. So the DOM was definitely ready.
Outside of a method callback it works fine.
Aha, I tried it in FireFox, and got this warning message!
document.execCommand(‘cut’/‘copy’) was denied because it was not called from inside a short running user-generated event handler.
So it seems the security policy of the browser doesn’t like it.