Notification texts go here Contact Us Buy Now!

Enable Double-Click to Copy on Blogger: Easy Tutorial

Learn how to enable double-click to copy functionality on your Blogger website with this easy tutorial. Improve user experience and convenience.
In this post, I'll explain how to enable a feature that allows visitors to double-click to copy text on your Blogger website.

Enable Double-Click to Copy on Blogger: Easy Tutorial

Adding this double-click functionality can greatly improve user experience, especially for mobile users who find it challenging to highlight and copy long pieces of text or code.

Below is the video tutorial on how to enable the double-click to copy functionality on your Blogger website.


Here's the code to enable double-click to copy to the clipboard on your Blogger website.

<style>
        .bottom-alert {
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background-color: #204ecf;
            color: #fff;
            padding: 10px;
            text-align: center;
            display: none;
            width: 200px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
           z-index: 999999;
        }
    </style>
<div class='bottom-alert' id='bottomAlert'>Code Copied!</div>

<script>
    var codeElements = document.querySelectorAll(".copyableCode");
    codeElements.forEach(function(element) {
        element.addEventListener("dblclick", function() {
            copyToClipboard(element);
        });
    });
    function copyToClipboard(element) {
        var tempTextArea = document.createElement("textarea");
        tempTextArea.value = element.textContent;
        document.body.appendChild(tempTextArea);
        tempTextArea.select();
        tempTextArea.setSelectionRange(0, 99999); 
        document.execCommand("copy");
        document.body.removeChild(tempTextArea);
        
        showBottomAlert();
    }
    function showBottomAlert() {
        var bottomAlert = document.getElementById("bottomAlert");
        bottomAlert.style.display = "block";
        setTimeout(function() {
            bottomAlert.style.display = "none";
        }, 3000);
    }
</script>

Make sure to assign the class "copyableCode" to the code box as demonstrated in the video. You can use multiple code boxes on the same page, and this feature will work smoothly across all of them.

About the Author

Proudly African 🇲🇼. Modern life, shaped by the echoes of traditional drums.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.