David Bonnici
David Bonnici

Reputation: 6747

Mozilla Firefox & Internet Explorer compatible clipboard in ASP.NET

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

Upvotes: 1

Views: 3344

Answers (2)

sabiland
sabiland

Reputation: 2614

For non-IE browsers use this common-all-over-the-world-used script. Google for "_clipboard.swf" file. (though, this code will NOT work on newest Flash 10 becouse of 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;

Upvotes: 0

Strelok
Strelok

Reputation: 51451

Internet Explorer clipboard copy 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 at all. Impossible actually with pure JS unless you have signed scripts etc. There is a workaround using a Flash object, however. Read about it here

Upvotes: 2

Related Questions