1

我需要使用 ASP.NET 将文本从文本框中复制到剪贴板。我想要一个与 Mozilla Firefox 和 IE 相媲美的代码。

4

2 回答 2

2

Internet Explorer 剪贴板副本很简单:

// 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,一点也不小。除非您已签署脚本等,否则实际上不可能使用纯 JS。但是,有一种使用 Flash 对象的解决方法。在这里阅读

于 2008-12-11T10:41:36.383 回答
0

对于非 IE 浏览器,请使用这个世界通用的脚本。谷歌搜索“_clipboard.swf”文件。(不过,出于安全原因,此代码不适用于最新的 Flash 10)

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;
于 2008-12-11T11:06:49.670 回答