how can I copy from my button "Copy URLs" when is clicked?
function cdwUrlsMDBE() {
var prd = document.getElementById("prd");
if (prd.checked == true) {
Swal.fire({
type: 'success',
html: 'i am a text that should be copy',
width: 'auto',
confirmButtonText: 'Copy URLs',
})
Thanks
You could do it creating a button via html and Bootstrap, in this way you could attach an handler on the button via onOpen.
Something like this
Swal.fire({
title: "Copy it!",
html:
'<textarea id="text_to_be_copied" class="swal2-input" readonly>Some text you want to copy</textarea>' +
'<button type="button" class="btn btn-default" id="btn-copy" style="margin-left:5px">Copy</button>' +
'<button type="button" class="btn btn-primary swal-confirm" id="btn-ok" style="float:right" disabled>Text have been copied!</button>' +
'</div>',
showConfirmButton: false,
type: "success",
onOpen: () => {
$("#btn-copy").click(() => {
$("#btn-ok").prop('disabled', false);
$("#text_to_be_copied").select();
document.execCommand("copy");
});
$("#btn-ok").click(() => {
Swal.close();
});
}
});
In this way the "confirmation button" is displayed only after you use the copy one, but you could decide to get rid of that just by putting Swal.close() inside the handler of the copy button. In this way after clicking che copy button, the popUp will close.
You could choose to use also an input tag instead of a textarea depends on your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With