js复制URL链接

html:

<div style="height:0px; text-indent:-10000px;"><span id="hdcopyurl" style="">http://www.baidu.com</span></div>
<a onClick="copyUrl()" style="cursor: pointer;">复制链接</a>

js:

<script>

function copyUrl() {
var clipBoardContent = document.getElementById("hdcopyurl");
window.getSelection().selectAllChildren(clipBoardContent);
document.execCommand("Copy");
alert('复制成功');
}

</script>

 

参考:https://www.cnblogs.com/MythLeige/p/9110621.html

posted @ 2018-06-29 14:47  Iwin9999  阅读(401)  评论(0编辑  收藏  举报