目前,如果使用javascript来写复制到剪贴板的代码,一般都是浏览器不兼容的。所以采用flash的方式,模拟一个层,再来复制,就可以做到全部浏览器都适用哦~
需要下载一个swf文件,和一个js文件。把这两个文件,和htm放到一起。
图示:
必须放在服务器端使用哦。
图示:
JS代码:
ZeroClipboard.js
// Simple Set Clipboard System
// Author: Joseph Huckaby
var ZeroClipboard = {
version: "1.0.7",
clients: {}, // registered upload clients on page, indexed by id
moviePath: 'ZeroClipboard.swf', // URL to movie
nextId: 1, // ID of next movie
$: function(thingy) {
// simple DOM lookup utility function
if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
if (!thingy.addClass) {
// extend element with a few useful methods
thingy.hide = function() { this.style.display = 'none'; };
thingy.show = function() { this.style.display = ''; };
thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
thingy.removeClass = function(name) {
var classes = this.className.split(/\s+/);
var idx = -1;
for (var k = 0; k if (classes[k] == name) { idx = k; k = classes.length; }
}
if (idx > -1) {
classes.splice( idx, 1 );
this.className = classes.join(' ');
}
return this;
};
thingy.hasClass = function(name) {
return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
};
}
return thingy;
},
setMoviePath: function(path) {
// set path to ZeroClipboard.swf
this.moviePath = path;
},
dispatch: function(id, eventName, args) {
// receive event from flash movie, send to client
var client = this.clients[id];
if (client) {
client.receiveEvent(eventName, args);
}
},
register: function(id, client) {
// register new client to receive events
this.clients[id] = client;
},
getDOMObjectPosition: function(obj, stopObj) {
// get absolute coordinates for dom element
var info = {
left: 0,
top: 0,
width: obj.width ? obj.width : obj.offsetWidth,
height: obj.height ? obj.height : obj.offsetHeight
};
while (obj && (obj != stopObj)) {
info.left += obj.offsetLeft;
info.top += obj.offsetTop;
obj = obj.offsetParent;
}
return info;
},
Client: function(elem) {
// constructor for new simple upload client
this.handlers = {};
// unique ID
this.id = ZeroClipboard.nextId++;
this.movieId = 'ZeroClipboardMovie_' + this.id;
// register client with singleton to receive flash events
ZeroClipboard.register(this.id, this);
// create movie
if (elem) this.glue(elem);
}
};
ZeroClipboard.Client.prototype = {
id: 0, // unique ID for us
ready: false, // whether movie is ready to receive events or not
movie: null, // reference to movie object
clipText: '', // text to copy to clipboard
handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
cssEffects: true, // enable CSS mouse effects on dom container
handlers: null, // user event handlers
glue: function(elem, appendElem, stylesToAdd) {
// glue to DOM element
// elem can be ID or actual DOM element object
this.domElement = ZeroClipboard.$(elem);
// float just above object, or zIndex 99 if dom element isn't set
var zIndex = 99;
if (this.domElement.style.zIndex) {
zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
}
if (typeof(appendElem) == 'string') {
appendElem = ZeroClipboard.$(appendElem);
}
else if (typeof(appendElem) == 'undefined') {
appendElem = document.getElementsByTagName('body')[0];
}
// find X/Y position of domElement
var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
// create floating DIV above element
this.div = document.createElement('div');
var style = this.div.style;
style.position = 'absolute';
style.left = '' + box.left + 'px';
style.top = '' + box.top + 'px';
style.width = '' + box.width + 'px';
style.height = '' + box.height + 'px';
style.zIndex = zIndex;
if (typeof(stylesToAdd) == 'object') {
for (addedStyle in stylesToAdd) {
style[addedStyle] = stylesToAdd[addedStyle];
}
}
// style.backgroundColor = '#f00'; // debug
appendElem.appendChild(this.div);
this.div.innerHTML = this.getHTML( box.width, box.height );
},
getHTML: function(width, height) {
// return HTML for movie
var html = '';
var flashvars = 'id=' + this.id +
'&width=' + width +
'&height=' + height;
if (navigator.userAgent.match(/MSIE/)) {
// IE gets an OBJECT tag
var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
html += '';
}
else {
// all other browsers get an EMBED tag
html += '';
}
return html;
},
hide: function() {
// temporarily hide floater offscreen
if (this.div) {
this.div.style.left = '-2000px';
}
},
show: function() {
// show ourselves after a call to hide()
this.reposition();
},
destroy: function() {
// destroy control and floater
if (this.domElement && this.div) {
this.hide();
this.div.innerHTML = '';
var body = document.getElementsByTagName('body')[0];
try { body.removeChild( this.div ); } catch(e) {;}
this.domElement = null;
this.div = null;
}
},
reposition: function(elem) {
// reposition our floating div, optionally to new container
// warning: container CANNOT change size, only position
if (elem) {
this.domElement = ZeroClipboard.$(elem);
if (!this.domElement) this.hide();
}
if (this.domElement && this.div) {
var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
var style = this.div.style;
style.left = '' + box.left + 'px';
style.top = '' + box.top + 'px';
}
},
setText: function(newText) {
// set text to be copied to clipboard
this.clipText = newText;
if (this.ready) this.movie.setText(newText);
},
addEventListener: function(eventName, func) {
// add user event listener for event
// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
if (!this.handlers[eventName]) this.handlers[eventName] = [];
this.handlers[eventName].push(func);
},
setHandCursor: function(enabled) {
// enable hand cursor (true), or default arrow cursor (false)
this.handCursorEnabled = enabled;
if (this.ready) this.movie.setHandCursor(enabled);
},
setCSSEffects: function(enabled) {
// enable or disable CSS effects on DOM container
this.cssEffects = !!enabled;
},
receiveEvent: function(eventName, args) {
// receive event from flash
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
// special behavior for certain events
switch (eventName) {
case 'load':
// movie claims it is ready, but in IE this isn't always the case...
// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
this.movie = document.getElementById(this.movieId);
if (!this.movie) {
var self = this;
setTimeout( function() { self.receiveEvent('load', null); }, 1 );
return;
}
// firefox on pc needs a "kick" in order to set these in certain cases
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
var self = this;
setTimeout( function() { self.receiveEvent('load', null); }, 100 );
this.ready = true;
return;
}
this.ready = true;
this.movie.setText( this.clipText );
this.movie.setHandCursor( this.handCursorEnabled );
break;
case 'mouseover':
if (this.domElement && this.cssEffects) {
this.domElement.addClass('hover');
if (this.recoverActive) this.domElement.addClass('active');
}
break;
case 'mouseout':
if (this.domElement && this.cssEffects) {
this.recoverActive = false;
if (this.domElement.hasClass('active')) {
this.domElement.removeClass('active');
this.recoverActive = true;
}
this.domElement.removeClass('hover');
}
break;
case 'mousedown':
if (this.domElement && this.cssEffects) {
this.domElement.addClass('active');
}
break;
case 'mouseup':
if (this.domElement && this.cssEffects) {
this.domElement.removeClass('active');
this.recoverActive = false;
}
break;
} // switch eventName
if (this.handlers[eventName]) {
for (var idx = 0, len = this.handlers[eventName].length; idx var func = this.handlers[eventName][idx];
if (typeof(func) == 'function') {
// actual function reference
func(this, args);
}
else if ((typeof(func) == 'object') && (func.length == 2)) {
// PHP style object + method, i.e. [myObject, 'myMethod']
func[0][ func[1] ](this, args);
}
else if (typeof(func) == 'string') {
// name of function
window[func](this, args);
}
} // foreach event handler defined
} // user defined handler for event
}
};
html代码:
a.htm
flash文件请自己到网上下载哈~

从“访达”查看macOS剪贴板历史记录当您在Mac上复制任何内容(文本,图像,文件,URL等)时,它会进入“剪贴板”。以下是查看Mac上上次复制的内容的方法。转到Finder,然后单击菜单栏中的“编辑”点击“显示剪贴板”这将打开一个窗口,显示macOS剪贴板的内容。在Mac中获取包含多个项目的剪贴板历史记录当然,本机Mac剪贴板历史记录并不是您可以拥有的最通用的工具。它只显示您复制的最后内容,因此,如果您希望一次复制多个内容,然后将它们全部粘贴在一起,那么您根本无法做到这一点。但是,如果您正在寻

检查你的键盘如果键盘快捷键不起作用,则键盘本身可能存在问题。确保它已正确插入并被您的PC识别。有笔记本电脑键盘给您带来麻烦吗?如果您有一个额外的键盘,请将其插入并查看它是否有效。如果是这样,那可能是键盘本身的问题。使用无线键盘?按照制造商的说明重新配对。您还应该检查任何电缆是否损坏,确保按键没有碎屑,然后适当按下。有关更多信息,请查看Windows11键盘损坏的这些修复程序。使用打印屏幕键如果您迫切需要屏幕截图并且没有时间进行故障排除,您可以先使用解决方法。要获得桌面的完整照片,请点击

iPhone上的剪贴板在哪里?由于iOS是一个封闭的生态系统,剪贴板是存储在虚拟内存中的内部功能。默认情况下,用户无法查看剪贴板内容或以任何方式对其进行编辑。但是,有一些方法可以在iPhone上访问剪贴板。您可以将剪贴板粘贴到Notes应用程序(或任何其他文本编辑器)中,并在其中保留剪贴板的多个副本,并根据需要对其进行编辑。或者,您可以使用“快捷指令”App创建用于显示剪贴板的快捷方式。最后,您可以使用第三方应用程序,例如粘贴。如何在iPhone上访问剪贴板?无论您喜欢使用内置的“备忘录”应用、

复制一直是保存和共享文件的好方法。它允许您创建手动备份、执行简单的传输,甚至是如果不复制可能会损坏原始文件的修改。但是,如果您在尝试使用WindowsPC上的剪贴板时遇到问题,这有时会很困难。一些Windows11用户最近无法在他们的系统上使用复制粘贴。由于多种原因,可能会出现此问题,如果您在同一条船上,那么您可以在PC上修复它。如何修复Windows11上的复制粘贴由于许多问题可能导致Windows上的复制粘贴出现故障,我们在下面列出了解决此问题的最常见解决方案。我们建议您从第一

<h2>在Windows11上使用剪贴板历史记录</h2><p>您仍然可以使用<strong>右键单击>复制</strong>并<strong>右键单击>粘贴</strong>或使用<strong>Ctrl+C</strong&

Windows11中的剪辑和屏幕截图在哪里?这是我们从一些可能刚安装新操作系统或第一次使用截图工具的读者那里得到的问题。该工具旨在截取计算机屏幕的任何或所有部分。为了将事情放在上下文中,PrintScreen键将拍摄您的屏幕的完整快照,但SnippingTool可调整为仅抓取您喜欢的区域。Windows10/11上的截图和屏幕截图在哪里?默认情况下,剪辑和屏幕截图保存到计算机的剪贴板。这意味着要检索它们,您只需将它们粘贴到您想要的应用程序中,例如MicrosoftPaint、Photo

微软向DevChannel发布了Windows11InsiderPreviewBuild25115。它引入了一项称为建议操作的新功能。微软用两张截图展示了它。我们仔细看看它是如何工作的。如何在Windows11中使用建议的操作打开任何应用程序并突出显示包含电话号码、日期或时间的文本。使用Ctrl+C或右键单击菜单将所选文本复制到剪贴板。应该会弹出一个带有闪电图标的工具提示,这是建议操作栏。微软将其描述为“内嵌轻量级UI”。该栏显示与剪贴板中的内容相对应的选项。如果您复制了

在Android和Windows11之间复制和粘贴文本注意:对于本文,我们使用的是Windows11,但该过程在Windows10上几乎相同。首先,您需要启用剪贴板历史记录功能(如果尚未启用)。您可以使用以下步骤启用它:单击“开始”或按Windows键以启动“开始”菜单并单击“设置”。当设置打开时,单击左侧的系统。向下滚动到右侧列表,然后从菜单中选择剪贴板选项。切换剪贴板历史选项On。在同一部分中,启用跨设备同步并选择自动同步我复制的文本。在Android上安装Microsof


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3汉化版
中文版,非常好用

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)