目前,如果使用javascript來寫複製到剪貼簿的程式碼,一般都是瀏覽器不相容的。所以採用flash的方式,模擬一個層,再來複製,就可以做到全部瀏覽器都適用哦~
需要下載一個swf文件,和一個js文件。把這兩份文件,和htm放在一起。
圖示:
必須放在伺服器端使用哦。
圖示:
JS程式碼:
ZeroClipboard.js
// 簡單設定剪貼簿系統
// 作者:Joseph Huckaby
var ZeroClipboard = {
version: "1.0.7",
clients : {}, // 在頁面上註冊的上傳客戶端,按id 索引
moviePath: 'ZeroClipboard.swf', // 電影的URL
nextId: 1, // 下一部電影的ID
$: function( thingy) {
// 簡單的DOM 找出實用函數
if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
if (! thingy.addClass) {
// 使用一些有用的方法擴充元素
thingy.hide = function() { this.style.display = 'none'; };
thingy.show = function() { this.style.display = ''; };
thingy.addClass = function(name) { this.removeClass(name); this.className = ' ' 名稱; };
thingy.removeClass = function(名稱) {
var classes = this.className.split(/s /);
var idx = -1;
for (var k = 0; k
}
if (idx > -1) {
classes.splice( idx, 1 ) ;
this.className = classes.join(' ');
}
傳回此;
};
thingy.hasClass = function(name) {
return !!this .className.match( new RegExp("\s*" name "\s*") );
};
}
歸還東西;
},
setMoviePath: function(path ( Flash 影片接收事件,傳送到客戶端
var client = this.clients[id];
if (client) {
client.receiveEvent(eventName, args);
}
} ,
register: function(id, client) {
// 註冊新的客戶端來接收事件
this.clients[id] = client;
},
getDOMObjectPosition: function( obj, stopObj) {
// 取得dom 元素的絕對座標
var info = {
left: 0,
top: 0,
寬度:obj.width ? obj.width : obj.offsetWidth,
高度: obj.height ? obj.height : obj.offsetHeight
};
while (obj && (obj != stopObj)) {
obj = obj.offsetParent;
}
回傳訊息;
},
Client: function(elem) { function(elem) {
// 新的簡單上傳客戶端的建構子
this.handlers = {};
// 唯一ID
this.id = ZeroClipboard.nextId ;
this.movieId = 'ZeroClipboardMovie_' this.id;
// 使用單例註冊客戶端以接收Flash 事件
ZeroClipboard.register(this.id, this);
// 建立電影
if (elem ) this.glue(elem);
}
};
ZeroClipboard.Client.prototype = {
id: 0, // 我們唯一的ID
ready: false, // 電影是否準備好接收事件
movie: null, //引用影片物件
clipText: '', // 複製到剪貼簿的文字
handCursorEnabled: true, // 是否顯示手形遊標,或預設指標遊標
cssEffects: true, // 啟用CSS 滑鼠對dom 容器的影響
handlers: null, // 使用者事件處理程序
glue: function(elem,appendElem, stylesToAdd) {
glue: function(elem,appendElem, stylesToAdd) {
glue: function(elem,appendElem, stylesToAdd) {
glue: function(elem,appendElem, stylesToAdd) {
glue: /🎜>//黏合到DOM 元素
// elem 可以是ID 或實際值DOM 元素物件
this.domElement = ZeroClipboard.$(elem);
// 浮動在物件上方,如果未設定dom 元素,則為zIndex 99
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) == '未定義') {
else if (typeof(appendElem) == '未定義') {
appendElem = document.getElementsByTagName('body')[0];
}
// 找出domElement 的X/Y 位置
var box = ZeroClipboard.getDOMObjectPosition(this.domElement,appendElem); 🎜>// 在元素上方建立浮動DIV
this.div = document.createElement('div');
var style = this.div.style;
style.position = '絕對';
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 (linkedStyle in stylesToAdd) {
style[addedStyle] = stylesToAdd[addedStyle];
}
}
// style.backgroundColor = '#f00'; // 調試
appendElem.appendChild(this.div); >this.div.innerHTML = this.getHTML( box.width, box.height );
},
getHTML: function(width, height) {
// 回傳影片的 HTML
var html = '';
var flashvars = 'id=' this.id
'&width='寬度
'&height='高度;
if (navigator.userAgent.match(/MSIE/)) {
// IE 取得 OBJECT 標籤
var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
html = '';
}
else {
//所有其他瀏覽器都會獲得EMBED 標籤
html = ' ';
}
回傳 html;
},
hide: function() {
//暫時螢幕外的隱藏浮動視窗
if (this.div) {
this.div.style.left = '-2000px ';
}
},
show: function() {
// 在呼叫 hide() 後顯示我們自己
this.reposition();
},
destroy: function() {
//焦點控制與浮動元素
if (this.domElement && this.div) {
this.hide();
this.div.innerHTML = '';
var body = document.getElementsByTagName('body')[0];
嘗試{ body.removeChild( this.div ); } catch(e) {;}
this.domElement = null;
this.div = null;
}
},
reposition: function(elem) {
//重新定位我們的浮動div,可以選擇到新的容器
// 警告:容器無法更改大小,更改位置
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) {
// 設定要複製到剪貼簿的文字
this.clipText = newText;
if (this.ready) this.movie.setText(newText);
},
addEventListener: function(eventName, func) {
//為事件新增使用者事件監聽器
//事件類型:load,queueStart,fileStart,fileComplete,queueComplete,progress,error ,取消
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
if (!this.handlers[eventName]) this.handlers[eventName] = [];
this.handlers[eventName].push(func);
},
setHandCursor: function(enabled) {
// 啟用手形識別 (true),或預設箭頭標識 (false)
this.handCursorEnabled =enabled;
if (this.ready) this.movie.setHandCursor(enabled);
},
setCSSEffects: function(enabled) {
// 啟用或停用 DOM 容器上的 CSS 效果
this.cssEffects = !!enabled;
},
receiveEvent: function(eventName, args) {
// 從 flash 接收事件
eventName = eventName.toString().toLowerCase().replace(/^on/, '' );
//某些事件的特殊行為
switch (eventName) {
case 'load':
// 電影聲稱它已經準備就緒,但在IE 中情況並不總是如此...
// 錯誤修復:無法在Firefox 中擴展EMBED DOM 元素,必須使用傳統函數
this.movie = document.getElementById(this.movieId) ; (!this.movie) {
var self = this
setTimeout( function() { self.receiveEvent('load', null); }, 1 );
返回; >}
// pc 上的firefox 需要「踢」才能在某些情況下設定這些
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(userAgent.match(userAgent.match(userAgent.match) /Windows/)) {
var self = this;
setTimeout( function() { self.receiveEvent('load', null); }, 100 );
this.ready = true; >返回;
}
this.ready = true;
this.movie.setText( this.clipText );
this.movie.setTextHandCursor( this.handCursorEnabled );
休息;
case 'mouseover':
if (this.domElement && this.cssEffects) {
this.domElement.addClass('hover');
if (this. recoverActive); this.domElement.addClass('active');
}
休憩;
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');
}
休憩;
case 'mousedown':
if (this.domElement && this.cssEffects) {
this.domElement.addClass('active');
}
休憩;
case 'mouseup':
if (this.domElement && this.cssEffects) {
this.domElement.removeClass('active');
this.recoverActive = false;
}
休憩;
} // イベント名を切り替えます
if (this.handlers[eventName]) {
for (var idx = 0, len = this.handlers[eventName].length; idx var func = this.handlers[eventName][idx];
if (typeof(func) == 'function') {
// 実際の関数参照
func(this, args);
}
else if ((typeof(func) == 'object') && (func.length == 2)) {
// PHP スタイルのオブジェクト メソッド、つまり [myObject, 'myMethod']
func[0][ func[1] ](this, args);
}
else if (typeof(func) == 'string') {
// 関数の名前
window[func](this, args);
}
} // foreach イベント ハンドラ定義
} // イベントのユーザー定義ハンドラ
}
};
html代:
a.htm
var クリップ = null;
function $(id) { return document.getElementById(id); }
function init() {
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
clip.addEventListener('load', function (client) {
debugstr("Flash ムービーがロードされ、準備ができました。");
});
clip.addEventListener('mouseOver', function (client) {
// マウスオーバー時のテキストを更新します
clip.setText( $('myresource').value );
});
clip.addEventListener('complete', function (client, text) {
debugstr("テキストをクリップボードにコピーしました: " text );
});
clip.glue( 'd_clip_button', 'd_clip_container' );
}
setTimeout(function(){
init();
},1500);

我使用您的日常技術工具構建了功能性的多租戶SaaS應用程序(一個Edtech應用程序),您可以做同樣的事情。 首先,什麼是多租戶SaaS應用程序? 多租戶SaaS應用程序可讓您從唱歌中為多個客戶提供服務

本文展示了與許可證確保的後端的前端集成,並使用Next.js構建功能性Edtech SaaS應用程序。 前端獲取用戶權限以控制UI的可見性並確保API要求遵守角色庫

JavaScript是現代Web開發的核心語言,因其多樣性和靈活性而廣泛應用。 1)前端開發:通過DOM操作和現代框架(如React、Vue.js、Angular)構建動態網頁和單頁面應用。 2)服務器端開發:Node.js利用非阻塞I/O模型處理高並發和實時應用。 3)移動和桌面應用開發:通過ReactNative和Electron實現跨平台開發,提高開發效率。

JavaScript的最新趨勢包括TypeScript的崛起、現代框架和庫的流行以及WebAssembly的應用。未來前景涵蓋更強大的類型系統、服務器端JavaScript的發展、人工智能和機器學習的擴展以及物聯網和邊緣計算的潛力。

JavaScript是現代Web開發的基石,它的主要功能包括事件驅動編程、動態內容生成和異步編程。 1)事件驅動編程允許網頁根據用戶操作動態變化。 2)動態內容生成使得頁面內容可以根據條件調整。 3)異步編程確保用戶界面不被阻塞。 JavaScript廣泛應用於網頁交互、單頁面應用和服務器端開發,極大地提升了用戶體驗和跨平台開發的靈活性。

Python更适合数据科学和机器学习,JavaScript更适合前端和全栈开发。1.Python以简洁语法和丰富库生态著称,适用于数据分析和Web开发。2.JavaScript是前端开发核心,Node.js支持服务器端编程,适用于全栈开发。

JavaScript不需要安裝,因為它已內置於現代瀏覽器中。你只需文本編輯器和瀏覽器即可開始使用。 1)在瀏覽器環境中,通過標籤嵌入HTML文件中運行。 2)在Node.js環境中,下載並安裝Node.js後,通過命令行運行JavaScript文件。

如何在Quartz中提前發送任務通知在使用Quartz定時器進行任務調度時,任務的執行時間是由cron表達式設定的。現�...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

Dreamweaver Mac版
視覺化網頁開發工具

記事本++7.3.1
好用且免費的程式碼編輯器