html代码点击复制微信号并自动打开微信添加好友

需要注意的是
<span id="target">xyz2018</span>这部分不能设置为“display:none” , 否则无法实现复制 , 如果不想展现id="target"的内容可以这样写#target{
display:block;
height:0px;
opacity: 0;
}
完整代码如下
<!DOCTYPE html>   
<html lang="en">   
<head>   
    <meta charset="UTF-8">   
    <script src=https://www.isolves.com/it/cxkf/yy/html5/2021-02-06/"http://libs.baidu.com/jquery/1.9.0/jquery.js">
    <script src=https://www.isolves.com/it/cxkf/yy/html5/2021-02-06/"https://cdn.jsdelivr.net/clipboard.js/1.5.12/clipboard.min.js">
    <title>复制按钮</title>   
</head>   
<body>   
<span id="target">这是我的微信号</span>
<button class="btn" data-clipboard-action="copy" data-clipboard-target="#target" id="copy_btn">   
    点击复制   
</button>   
</body>   
<script>   
    $(document).ready(function(){     
        var clipboard = new Clipboard('#copy_btn');   
        clipboard.on('success', function(e) {   
            alert("微信号复制成功",1500);
            window.location.href=https://www.isolves.com/it/cxkf/yy/html5/2021-02-06/'weixin://';
            e.clearSelection();   
            console.log(e.clearSelection);   
        });   
    });   
</script>   
</html>

alert弹窗去掉上方网址标题window.alert = function (name)
{
const iframe = document.createElement('IFRAME');
iframe.style.display = 'none';
iframe.setAttribute('src', 'data:text/plain,');
document.documentElement.AppendChild(iframe); window.frames[0].window.alert(name);
iframe.parentNode.removeChild(iframe);
};
【html代码点击复制微信号并自动打开微信添加好友】


    推荐阅读