Last active
March 2, 2019 21:06
-
-
Save neotam/7a7b2809515aeae244bb6e27be872fc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function writeToClipboardOnPermission(text){ | |
navigator.permissions.query({name:'clipboard-write'}) | |
.then( | |
result => { | |
if (result.state == 'granted' || result.state == 'prompt'){ | |
writeToClipboard(text); | |
} | |
else { | |
console.log("Don't have permissions to use clipboard", result.state); | |
} | |
} | |
) | |
.catch( | |
err => { | |
console.log("Error! Reqeusting permission", err) | |
} | |
) | |
} | |
function writeToClipboard(text) { | |
navigator.clipboard.writeText(text).then( | |
result => { | |
console.log("Successfully copied to clipboard", result) | |
} | |
) | |
.catch( | |
err => { | |
console.log("Error! could not copy text", err) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment