كيفية عمل زر copy to clipboard

ma2500

السلام عليكم اريد انشاء زر عند الضغط عليه يتم نسخ الكوبون الموجود

كيف ذلك جربت هذا الكود ولم ينجح

لا ادري ما المشكلة هل هناك حل بارك الله فيكم العمل بالووردبريس اخذت شفرة html بالمنتور ووضعت الكود

<!-- The text field -->

<input type="text" value="seev" id="myInput">

<!-- The button used to copy the text -->

<button onclick="myFunction()">انسخ الكود</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>


التعليق السابق

جزاك الله خير في احد المتصفحات لم يعمل لكن الان عمل بشكل جيد بارك الله فيك