Compatible clipboard Mozilla Firefox and Internet Explorer in ASP.NET

I need to copy text from a textbox to the clipboard using ASP.NET. I need code that is comparable to Mozilla Firefox and IE.

+1


source to share


2 answers


Copying the Internet Explorer clipboard is trivial:

// set the clipboard
var x = 'Whatever you want on the clipboard';
window.clipboardData.setData('Text',x);

// get the clipboard data
window.clipboardData.getData('Text');

      



Firefox, not trivial. Not really possible with pure JS unless you signed scripts, etc. However, the workaround is using the Flash object. Read about it here

+2


source


For non-IE browsers use this generic script shared globally. Google for the file "_clipboard.swf". (although this code will NOT work on the newest Flash 10 for security reasons)

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='+encodeURIComponent('YOUR_VALUE_FOR_CLIPBOARD')+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
     document.getElementById(flashcopier).innerHTML = divinfo;

      

0


source







All Articles