735 votes
0 answers
javascript - Tap to copy discount code is not working in cart drawer Shopify
Solution:
i have solved this problem using java script. here is the code :-
function myFunction()
{
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
$(".tooltiptext").show();
setTimeout(function() {
$('.tooltiptext').fadeOut('fast');
}, 200);
}
.copy_coupon{position:relative;}
.tooltiptext{display: none;
position: absolute;
background: rgb(0 0 0 / 61%);
color: rgb(255, 255, 255);
top: -25px;
padding: 2px 12px;
border-radius: 5px}
<div class="coupon_container">
<div class="left_text">
<strong>FLAT 50% OFF ON FIRST ORDER</strong>
<small>*Applicable on single units.</small>
</div>
<button class="coupon_tab" onclick="myFunction()">
<span class="copy_coupon" >
<small class="tooltiptext">Copied</small>
<small>Tap Here to Copy</small>
<strong>FIRST50</strong>
</span>
</button>
</div>
<input type="text" value="FIRST50" id="myInput" style="width:auto;" >
Undefined asked
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.