Why doesn't copying work on Safari?

Joined
Oct 31, 2024
Messages
1
Reaction score
0
I have already written several asynchronous functions (when we click on the button, the text is copied), it works on Chrome and Edge, but not on Safari. I can't understand what the problem is.
 
Joined
Jul 4, 2023
Messages
589
Reaction score
78
Clipboard API Compatibility, ensure that the navigator.clipboard API is fully supported. Safari, especially older versions, may not support navigator.clipboard.writeText() as consistently as Chrome or Edge.

Check if the API is supported:
JavaScript:
async function copyText() {
  if (navigator.clipboard && navigator.clipboard.writeText) {
    try {
      await navigator.clipboard.writeText("Text to copy");
      console.log("Text copied successfully!");
    } catch (err) {
      console.error(err);
    }
  } else {
    console.log("Clipboard API is not supported in this browser.");
  }
}

copyText();
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top