forked from lgarron/clipboard-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
68 lines (60 loc) · 2.1 KB
/
index.html
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
<html>
<head>
<title>Web Clipboard</title>
<script src="clipboard.js"></script>
</head>
<body>
<button id="plain-copy">Copy text (plain)</button>
<span id="plain-copy-result"></span>
<script>
document.getElementById("plain-copy").addEventListener("click", function() {
clipboard.copy("This text is plain.").then(function(){
document.getElementById("plain-copy-result").textContent = "success";
}, function(err){
document.getElementById("plain-copy-result").textContent = err;
});
});
</script>
<hr>
<button id="markup-copy">Copy text (markup)</button>
<span id="markup-copy-result"></span>
<script>
document.getElementById("markup-copy").addEventListener("click", function() {
clipboard.copy({
"text/plain": "Markup text. Paste me into a rich text editor.",
"text/html": new XMLSerializer().serializeToString(document.body)
}).then(function(){
document.getElementById("markup-copy-result").textContent = "success";
}, function(err){
document.getElementById("markup-copy-result").textContent = err;
});
});
</script>
<hr>
<button id="markup-dom-copy">Copy markup (DOM node → markup)</button>
<span id="markup-dom-copy-result"></span>
<br>
<span id="markup-dom-copy-source" style="font-family: Helvetica;"><i><span style="font-size: 150%">T</span>his</i> <span style="background: orange; padding: 0px 2px">will be</span> <b>copied</b>.</span>
<script>
document.getElementById("markup-dom-copy").addEventListener("click", function() {
clipboard.copy(document.getElementById("markup-dom-copy-source")).then(function(){
document.getElementById("markup-dom-copy-result").textContent = "success";
}, function(err){
document.getElementById("markup-dom-copy-result").textContent = err;
});
});
</script>
<hr>
<button id="paste">Paste</button>
<span id="paste-result"></span>
<script>
document.getElementById("paste").addEventListener("click", function() {
clipboard.paste().then(function(result) {
document.getElementById("paste-result").textContent = result;
}, function(err) {
document.getElementById("paste-result").textContent = err;
});
});
</script>
</body>
</html>