Please i need clipboard copy function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tamilmani
Forum Commoner
Posts: 39
Joined: Tue Apr 01, 2008 2:53 am

Please i need clipboard copy function

Post by tamilmani »

I need functionality for copy the textarea content and paste into my notepad itself.
I am searching in net also they available for IE only . I need compatability for all browsers.

Please urgently i need this.......
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Please i need clipboard copy function

Post by Eric! »

I don't quite understand what you want. The textarea is displayed on your browser or do you want to extract it remotely?

You have to access the clipboard on the client side, so try javascript. Here is how you set and get text with a javascript in IE.

Code: Select all

var bResult =
window.clipboardData.setData("Text","SAMPLE");
var text = window.clipboardData.getData("Text");
alert('window.clipboardData: '+text);
In mozilla/firefox it is a bit more involved see http://www.logiclabz.com/javascript/cop ... nd-ie.aspx

Code: Select all

function copy_to_clipboard(text)
{
    if(window.clipboardData)
    {
    window.clipboardData.setData('text',text);
    }
    else
    {
        var clipboarddiv=document.getElementById('divclipboardswf');
    if(clipboarddiv==null)
    {
       clipboarddiv=document.createElement('div');
           clipboarddiv.setAttribute("name", "divclipboardswf");
       clipboarddiv.setAttribute("id", "divclipboardswf");
       document.body.appendChild(clipboarddiv);
    }
        clipboarddiv.innerHTML='<embed src="clipboard.swf" FlashVars="clipboard='+
encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    }
    alert('The text is copied to your clipboard...');
    return false;
}
 
Edit: while the swf technique works on my mozilla microbrowser, it is generally considered a security risk for the browser to access clipboard data and I think some versions now block this.
Post Reply