Why does `navigator.clipboard.writeText` not copy text to clipboard if it is proceeded by alert() on android

Because the navigator.clipboard.writeText method returns a promise and your code does not wait for its result.

If you correct code as shown below then it should be fine:

function myFunction() {
    var copyText = document.getElementById("myInput");
    copyText.select();
    copyText.setSelectionRange(0, 99999);
    navigator.clipboard
      .writeText(copyText.value)
      .then(() => {
        alert("successfully copied");
      })
      .catch(() => {
        alert("something went wrong");
      });
}

For further information about Promise and the navigator.clipboard.writeText method, please visit the following links:
Promise on JavaScript.info
Interact with the clipboard on MDN

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)