I am trying to copy content to the clipboard using JS in an angular app.
Unfortunately, document.queryCommandEnabled("copy") will consistently return false . Is there any way to understand why the browser refuses to execute the command? What is the criterion for including a team?
code:
function copyText(text) { var input = document.createElement('textarea'); document.body.appendChild(input); input.value = text; input.focus(); input.select(); var success = document.execCommand('Copy'); input.remove(); return success; }
I am testing if the command is enabled before running this function:
if(document.queryCommandEnabled("copy")) // Always return false executeCopy(text_value);
source share