Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Javascript: how to stop Javascript from Clipboard automatically copying text to clipboard?

I have a simple function that would copy text to clipboard when a user click the Copy Link button, but i noticed that whenever i navigate to the page where i am supposed to copy the link from, it automatically gets copied, even if i havent clicked on the copy link button.

How do i stop this?

This is the code i wrote

<input readonly type="text" class="form-control w-50" value="{{ url_string }}" id="myInput" />
<!-- The button used to copy the text -->
<button onclick="myFunction()" id="copy-btn" class="btn btn-success">Copy Ref. Link</button>
<script>
    function myFunction() {
        /* Get the text field */
        var copyText = document.getElementById("myInput");

        /* Select the text field */
        copyText.select();
        copyText.setSelectionRange(0, 99999); /* For mobile devices */

        /* Copy the text inside the text field */
        navigator.clipboard.writeText(copyText.value);

        // Change button innerHTML Text
        document.getElementById("copy-btn").innerHTML = "Copied Successfully";

        /* Alert the copied text */
        // alert("Copied the text: " + copyText.value);
    }
</script>

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!