Kennt sich jemand mit Javascript aus? Ich will machen das wenn man auf einen Text drückt, das dieser kopiert wird. Ich habe auf einer Website nur den Code gefunden für <input> aber ich will es gerne mit <a> machen damit der Text normal aussieht.
Diesen Code benutze ich momentan und es funktioniert nicht:
Code
<script src="https://cdn.jsdelivr.net/gh/leonardosnt/mc-player-counter/dist/mc-player-counter.min.js"></script>
There are <span data-playercounter-ip="cubecraft.net">0</span> players on Hypixel right now. <br>
<!-- The text field -->
IP:
<!--<input type="text" value="Play.Tibuscraft.net" id="myInput" onclick="myFunction()" title="Click to copy"> <br>-->
<a class="test" value="play.korexnetwork.net" id="myInput" onclick="myFunction()" title="Click to copy">Play.Tibuscraft.net</a>
<!-- The button used to copy the text -->
<!--<button onclick="myFunction()">Copy text</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);
// Alert the copied text
alert("Copied the text: " + copyText.value);
}
</script>
<style>
input {
cursor: pointer;
}
.test {
cursor: pointer;
}
</style>
Alles anzeigen