本地分享代码

粤桂航友 粤桂航友 关注 进阶成员
发表于只有源码版块 其他
<style>
.share-wrap{text-align:center;margin:0;padding:0;background:transparent;box-shadow:none;}
.share-wrap h4{font-size:17px;color:#222;margin:0 0 10px;font-weight:600;max-width:360px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
#qrcode{width:180px;height:180px;margin:0 auto 10px;}
.guide-text{font-size:14px;color:#666;margin-bottom:8px;}
#shareUrl{display:block;margin:0 auto;width:240px;padding:10px 12px;border:1px solid #eee;border-radius:8px;font-size:14px;text-align:center;cursor:pointer;background:#f8f8f8;transition:all 0.2s ease;outline:none;}
#shareUrl:hover{border-color:#07C160;background:#f0fdf4;}
.tip-text{margin-top:8px;color:#07C160;font-size:14px;height:20px;line-height:20px;}
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
<div class="share-wrap">
<h4 id="shareTitle"></h4>
<div id="qrcode"></div>
<div class="guide-text">点击链接框 自动复制链接</div>
<input type="text" id="shareUrl" readonly onclick="copyUrl()">
<div class="tip-text" id="tipText"></div>
</div>
<script>
let currentUrl=window.location.href;let postTitle='';
window.onload=function(){
let h1Dom=document.querySelector('h1');
postTitle=h1Dom?h1Dom.innerText.trim():document.title.trim();
document.getElementById('shareTitle').innerText=postTitle;
new QRCode(document.getElementById('qrcode'),{text:currentUrl,width:180,height:180});
document.getElementById('shareUrl').value=currentUrl;
};
function copyUrl(){
let copyText=postTitle+"\n"+currentUrl;
let textarea=document.createElement('textarea');
textarea.value=copyText;document.body.appendChild(textarea);
textarea.select();document.execCommand('copy');
document.body.removeChild(textarea);
let tip=document.getElementById('tipText');
tip.innerText='✅ 复制成功,可直接分享';
setTimeout(()=>{tip.innerText='';},3000);
}
</script>

Image

本文章最后由 粤桂航友2026-05-04 14:09 编辑
评论列表 评论
发布评论

评论: 本地分享代码

(0) 分享
分享
取消
免责声明

资源密码:yghy

本站资源,均来自网络,版权归原作者,所有资源和文章仅限用于学习和研究目的。
不得用于商业或非法用途,否则,一切责任由该用户承担!
您必须在下载后的24个小时之内,从您的电脑&手机中彻底删除下载的资源
资源失效,举报投诉,建议意见等,都可以来反馈。综合反馈


侵权删除请致信 E-Mail:yghyou@qq.com