Copy URL button code

Discussion in 'HTML & Website Design' started by jackburd, Dec 28, 2011.

  1. #1
    Can anyone help me or provide me a code that allows user to copy URL of the site.
    Usually, it's a button that you click and then the URL of the site is copied to your clipboard.

    php, javascript, or jquery will do.

    Thanks a bunch!!!
     
    jackburd, Dec 28, 2011 IP
  2. sadhan.digital

    sadhan.digital Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    function copy(s) {
    if (window.clipboardData && clipboardData.setData)
    clipboardData.setData("Text", s);
    }
    <?php
    $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    ?>
    <div onclick="copy(<?php echo $url;?>)">Click to copy url</div>

    Thanks.
     
    sadhan.digital, Dec 31, 2011 IP