URL Shortener Copy To Clipboard Javascript with PHP

Discussion in 'PHP' started by MarketingPirate, Jul 22, 2008.

  1. #1
    I am looking for alittle help with this. I am not very familar with PHP. Actually I take that back. I have taken a crash course to make some cosmetic changes. Other than that I don't know crap.

    I have the javascript to cause an action to be created to clipboard (see below). The problem that I am having is that I want the item that is copied to the clip board be based on the new shortened url that is created. What goes in the copy('')? Should this be placed in the php brackets or not?This is the same javascript that TinyURL uses. Thanks for all your help.

    
    <script type="text/javascript" language="javascript"><!--
    function copy(text2copy) {
      if (window.clipboardData) {
        window.clipboardData.setData("Text",text2copy);
      } else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
          var divholder = document.createElement('div');
          divholder.id = flashcopier;
          document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
      }
    }
    
    copy('WHAT GOES HERE???');
    document.getElementById('copyinfo').innerHTML = "To paste it in a document, press and hold down the ctrl key while pressing the V key, or choose the &quot;paste&quot; option from the edit menu.<br />";
    
    //-->
    </script>
    
    Code (markup):
     
    MarketingPirate, Jul 22, 2008 IP
  2. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Lol, well what they do is in their 'create.php' script they do something like:

    
    // Create and store the 'tiny url'
    // Echo javascript function "copy"
    // $theTinyLink = generated link, like http://tinyurl.com/8kp
    
    echo "copy('" . $theTinyLink . ");";
    
    PHP:
    Then it just echo's the link that is generated, when the page loads the javascript is executed and the link is copied over. So yes, technically it has to be in <? ?> but basically your just echoing the javascript function and link.
     
    ToddMicheau, Jul 22, 2008 IP
    MarketingPirate likes this.
  3. MarketingPirate

    MarketingPirate Peon

    Messages:
    82
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey man thank you so much for you help. You really know your PHP. If I know anyone that needs a programmer I will send them your way!
     
    MarketingPirate, Jul 23, 2008 IP