javascript
1<html>
2<head>
3<script>
4function doCopy(txt){
5 var ta = document.createElement("textarea");
6 document.getElementsByTagName("body")[0].appendChild(ta);
7 ta.value=txt;
8 ta.select();
9 document.execCommand('copy');
10 ta.parentNode.removeChild(ta);
11}
12</script>
13</head>
14<body>
15<input type="button" value="copy hoge" onclick="doCopy('hoge')">
16<input type="button" value="copy fuga" onclick="doCopy('fuga')">
17</body>
18</html>
19
ある程度標準化されているようですが、動かない場合はもうすこし工夫が必要です
追記
そう言えばaのテキストを取りたいんでしたね
その分を追記しておきます
javascript
1<html>
2<head>
3<script>
4document.addEventListener('click',function(e){
5 var t=e.target;
6 if(t.nodeName=="A"){
7 doCopy(t.firstChild.nodeValue);
8 }
9});
10function doCopy(txt){
11 var ta = document.createElement("textarea");
12 document.getElementsByTagName("body")[0].appendChild(ta);
13 ta.value=txt;
14 ta.select();
15 var ret = document.execCommand('copy');
16 ta.parentNode.removeChild(ta);
17}
18</script>
19</head>
20<body>
21<input type="button" value="copy hoge" onclick="doCopy('hoge')">
22<input type="button" value="copy fuga" onclick="doCopy('fuga')">
23<a href="http://example.com">piyo</a>
24</body>
25</html>
26