起初的原因是对方复制网站内容顺带复制网址,我想能不能做加一个一键分享呢?顺带把页面的meta标签内的内容也加上。在网上找到了方法都是分开了,主要是提取META是分开的。但方法有人提就有人解决。一键复制网址标题URL及描述js分享,放到你的JS文件内。
function copytitleurl() {
var metadescription = document.querySelector('meta[name="description"]').getAttribute('content');//meta标签内容
var copyText = window.location.href;//当前网址
var elem = document.createElement("textarea");
document.body.appendChild(elem);
elem.value = document.title + '\n' + metadescription + '\xa0' + '......' + '\n' + '详情访问:' + copyText;
elem.select();
document.execCommand("copy");
document.body.removeChild(elem);
alert("复制成功!您可以粘贴分享啦");
}
引用方法:<button onclick="copytitleurl()">分享</button>