admin管理员组文章数量:1289620
I am trying to implement a copy-to-clipboard button on a webpage. Below is the code I have written
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
<script src=".11.1/jquery.min.js">
</script>
<p id="p1">Text1</p>
<p id="p2">Text2</p>
<button onclick="copyToClipboard('#p1')">Copy Text1</button>
<button onclick="copyToClipboard('#p2')">Copy Text2</button>
<br/><br/>
<input type="text" placeholder="Paste here for test" />
I am trying to implement a copy-to-clipboard button on a webpage. Below is the code I have written
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<p id="p1">Text1</p>
<p id="p2">Text2</p>
<button onclick="copyToClipboard('#p1')">Copy Text1</button>
<button onclick="copyToClipboard('#p2')">Copy Text2</button>
<br/><br/>
<input type="text" placeholder="Paste here for test" />
However, this does not seem to work on IE 9, 11 and Safari. Is there any change/alternate implementation I can use to implement this on my webpage.
Share Improve this question edited Aug 9, 2016 at 5:23 Mukesh Ram 6,3384 gold badges20 silver badges37 bronze badges asked Dec 23, 2015 at 11:11 BountyHunterBountyHunter 1,4112 gold badges24 silver badges36 bronze badges 1- Answer will get from link here – Jaydip Jadhav Commented Dec 23, 2015 at 11:27
1 Answer
Reset to default 8Not sure about Safari, but on IE you can do:
window.clipboardData.setData('Text', 'text you want to copy goes here');
I hope it helps. Cheers
本文标签: javascriptCopy to clipboard option for IE9IE11 and SafariStack Overflow
版权声明:本文标题:javascript - Copy to clipboard option for IE9, IE11 and Safari - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741472918a2380714.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论