网页点击链接复制微信代码


<style>
        .wechat-popup {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.7);
            z-index: 9999;
        }
.popup-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 15px 15px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    color: #1677ff;
}
.popup-content button {
    margin-top: 15px;
    padding: 5px 15px;
    background: #206fdd;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
    </style>
    <a href="javascript:;" onclick="copyWechat()" style="cursor: pointer; color: #07c160;">
        点击复制客服微信 
    </a>
 
    <div class="wechat-popup" id="wechatPopup">
        <div class="popup-content">
            <p>客服微信已复制,请打开微信</p>
            <button onclick="closePopup()">确定</button>
        </div>
    </div>
 
<script>
function copyWechat() {
    const wechatId = '客服微信号';
    copyToClipboard(wechatId);
    showPopup();
}
 
// 剪贴板操作(兼容方案)
function copyToClipboard(text) {
    if(navigator.clipboard)  {
        navigator.clipboard.writeText(text).catch(err  => {
            console.error(' 复制失败:', err);
        });
    } else {
        // 兼容旧版浏览器[2]()
        const textarea = document.createElement('textarea'); 
        textarea.value  = text;
        textarea.style.position  = 'fixed';
        document.body.appendChild(textarea); 
        textarea.select(); 
        try {
            document.execCommand('copy'); 
        } catch (err) {
            console.error(' 复制失败:', err);
        }
        document.body.removeChild(textarea); 
    }
}
 
// 显示提示弹窗[3]()
function showPopup() {
    const popup = document.getElementById('wechatPopup'); 
    popup.style.display  = 'block';
    // 8秒后自动关闭 
    setTimeout(closePopup, 8000);
}
 
function closePopup() {
    document.getElementById('wechatPopup').style.display  = 'none';
}
</script>

上一篇:网页调动打开手机QQ代码
下一篇:没了
最新回复 (0)
返回