// facebook,linkedin,twitter分享
let obj = {
href: "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(window.location.href),
target: "_blank",
specs: "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=600, height=450,top=100,left=350"
};
switch (value) {
case "facebook":
obj.href = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(window.location.href);
break;
case "linkedin":
obj.href = "http://www.linkedin.com/shareArticle?mini=true&url=" + encodeURIComponent(window.location.href);
break;
case "twitter":
obj.href = "https://twitter.com/intent/tweet?text=&url=" + encodeURIComponent(window.location.href);
break;
default:
break;
}
window.open(obj.href, obj.target, obj.specs);
还需要以下的内容在<head></head>里边加(时间久了有点忘了需要重新试下)
<meta property="og:url" content="分享链接的url" />
<meta property="og:description" content="分享的description" />
<meta property="og:image" content="分享图片的url" />
<meta property="og:title" content="分享内容的title" />
浏览器自带的分享
let title = document.querySelector("title") ? document.querySelector("title").innerText : "";
let text = document.querySelector('meta[name="description"]') ? document.querySelector('meta[name="description"]').getAttribute("content") : "";
let url = window.location.href;
if (navigator.share) {
navigator
.share({
title: title,
text: text,
url: url
})
.then(() => {})
.catch(console.error);
}
浏览器自带的分享适配
Navigator.share - Web API 接口参考 | MDN (mozilla.org)

1418

被折叠的 条评论
为什么被折叠?



