一开始去ZeroclipBoard 官网下载最新版本(2.x),后来才发现根本就不支持IE浏览器,IE浏览器打开官网也是报错。
ZeroclipBoard 的git有一段说明:
ZeroClipboard v2.x is expected to work in IE9+ and all of the evergreen browsers.
Although support for IE7 & IE8 was officially dropped in v2.0.0,
it was actuallystill technically supported through v2.0.2.
https://github.com/zeroclipboard/zeroclipboard
现在改成1.x版本,兼容IE浏览器:
/**
* @author default.fu@foxmail.com
* @description 复制 为了兼容IE9- ZeroClipboard 放弃2.x使用1.x版本
* @param $o
* @param text
*/
function initCopy($o, text) {
if (typeof text == 'undefined') {
if ($o instanceof jQuery) {
text = $o.val() || $o.html() || $o.text() || 'NULL';
} else {
if (typeof $o.value != 'undefined') {
text = $o.value;
} else if (typeof $o.innerHTML != 'undefined') {
text = $o.innerHTML;
} else {
text = 'NULL';
}
}
}
var client = new ZeroClipboard($o);
client.on('load', function (client) {
client.on('datarequested', function (client) {
client.setText(text);
});
client.on('complete', function (client, args) {
alert('复制成功 ' + text);
});
});
client.on('wrongflash noflash', function () {
alert('flash error');
ZeroClipboard.destroy();
});
}