1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//点击复制
var ClipBoard = function (obj) {
this.handlerID = obj.handlerID || null;
this.textID = obj.textID || null;
this.type = obj.type || 'copy';
this.isAttr = obj.isAttr || false;
this.isPlugin = true;
this.isActive = false;
var ua = window.navigator.userAgent;
var is_IE = ua.match(/(rv:|msie )\d+/i);
var IE_Version = is_IE ? parseInt(is_IE[0].split(/:| /g)[1]) : 9;
if (IE_Version <= 8) {
this.isPlugin = false;
}
var handlerObj = document.getElementById(obj.handlerID);
if (typeof this.type === 'string') {
handlerObj.setAttribute('data-clipboard-action', this.type)
} else {
throw error('type类型错误!');
}
if (!obj.isAttr && obj.textID) {
handlerObj.setAttribute('data-clipboard-target', '#' + obj.textID);
}
}
ClipBoard.prototype.attach = function () {
if (this.isActive) { // 对象已经被实例化
return;
}
var tip = '复制';
if (this.type === 'cut') {
tip = '剪切';
}
this.isActive = true;
if (this.isPlugin) {
var clip = new Clipboard('#' + this.handlerID);
clip.on('success', function (e) {
alert(tip + '成功!');
});
clip.on('error', function (e) {
//alert(e.action + '操作失败!');
alert('当前系统不支持,请手动复制(长按文字选择“拷贝”)');
});
} else if (window.attachEvent) {
var self = this;
var handlerObj = document.getElementById(this.handlerID);
handlerObj.attachEvent('onclick', function () {
var text = '';
if (self.isAttr) {// 复制属性值
text = handlerObj.getAttribute('data-clipboard-text');
} else {
var textObj = document.getElementById(self.textID);
text = textObj.value || textObj.innerHTML;
}
window.clipboardData.setData('Text', text);
alert(tip + '成功,可通过Ctrl+V进行粘贴!');
});
} else {
alert('浏览器版本过低,不支持该插件!');
}
}
var c1 = new ClipBoard({
handlerID: 'iosCopyBtn',
textID: 'link',
isAttr: false,
type: 'copy'
});
c1.attach(); // 触发复制/剪切功能
$(function () {
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsAndroid) {
$('#iosCopyBtn').hide();
$('#androidCopyBtn').show();
} else {
$('#androidCopyBtn').hide();
};
if (bIsAndroid || bIsIphoneOs || bIsIpad || bIsMidp || bIsUc7 || bIsUc || bIsCE || bIsWM) {
}
});
var CouponFun = function () {
//基本
var Coupon_fun = function () {
//复制
$("#androidCopyBtn").click(function () {
var e = document.getElementById("link");
e.select();
document.execCommand("Copy");
alert("已复制");
});
};
return {
init: function () {
Coupon_fun();
}
}
}();
CouponFun.init();