0

I am having a problem when copying values. I use Clipboard API but know Clipboard API only works with secure context (HTTPS), in my Beta it's only HTTP so Clipboard API doesn't work. So is there a way to use document.execCommand("copy") in this case? I can simulate my code that is having problems as follows:

let path = 'https://google.com' 
if(navigator.clipboard) {
  navigator.clipboard.writeText(path).then(function() {
    console.log("Success!")
  }, function() {
    console.log("Failed!")
  });
} else {
  // Using document.execCommand("copy")
  path.select();
  document.execCommand("copy");
}

And the problem I have is: Uncaught TypeError: path.select is not a function

Can someone help me with the use case of document.execCommand("copy")? Thanks very much

5
  • please tag this with the programming language you are using Commented Feb 24, 2022 at 14:35
  • please describe the problem you are having? What is wrong with your code currently Commented Feb 24, 2022 at 14:38
  • Sorry for the inconvenience. I have updated the above Commented Feb 24, 2022 at 14:52
  • The error doesn't seem to have anything to do with document.execCommand("copy");, rather with path.select();. Strings do not have a select() function in JS. What are you trying to accomplish with that line? Commented Feb 24, 2022 at 14:57
  • I'm trying to copy that path because in my beta it's HTTP so the Clipboard API doesn't work with this context. Commented Feb 24, 2022 at 15:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.