search
HomeWeb Front-endJS TutorialJS/FLASH implements copying code to the clipboard (compatible with all browsers)_javascript skills

Currently, if you use JavaScript to write code copied to the clipboard, it is generally incompatible with browsers. So use flash to simulate a layer and then copy it, so that it can be applied to all browsers~

You need to download a swf file and a js file. Put these two files together with htm.
Icon:


Must be used on the server side.
Icon:


JS code:
Copy code The code is as follows:

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


Zero Clipboard Test




Copy To Clipboard...








flash文件请自己到网上下载哈~
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在Mac上查看剪贴板历史记录如何在Mac上查看剪贴板历史记录Sep 14, 2023 pm 12:09 PM

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

怎样解决 Windows + Shift + S 无法正常使用的问题?怎样解决 Windows + Shift + S 无法正常使用的问题?May 08, 2023 pm 07:16 PM

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

如何解决 Windows 11 复制粘贴功能无响应的问题?如何解决 Windows 11 复制粘贴功能无响应的问题?Apr 26, 2023 pm 08:55 PM

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

iPhone上的剪贴板:如何访问它?iPhone上的剪贴板:如何访问它?May 16, 2023 am 10:46 AM

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

如何在 Windows 11 上使用剪贴板历史记录如何在 Windows 11 上使用剪贴板历史记录Apr 19, 2023 pm 12:13 PM

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

截图和截图在 Windows 11/10 上的位置截图和截图在 Windows 11/10 上的位置May 16, 2023 pm 04:01 PM

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

我们仔细研究了 Windows 11 中的建议操作,并向您展示如何禁用它我们仔细研究了 Windows 11 中的建议操作,并向您展示如何禁用它Apr 14, 2023 pm 03:10 PM

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

在 Android 和 Windows 平台之间复制和粘贴文本的方法在 Android 和 Windows 平台之间复制和粘贴文本的方法Apr 25, 2023 pm 10:43 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor