标题Facebook、Twitter、LinkedIn分享
//分享中携带的图片
<meta property="og:image" content="图片链接地址" />
//指定分享的跳转链接
//可以试用a标签,也可以试用js点击事件调用,反正最后跳转链接一定下面的几个,怎么做自己看着办吧
//twitter分享
"http://twitter.com/intent/tweet?url=" + encodeURIComponent(document.location.href) + " " + encodeURIComponent(document.title);
//facebook
"http://www.facebook.com/sharer.php?u=" + encodeURIComponent(document.location.href) + "&t=" + encodeURIComponent(document.title);
//linkedin
"http://www.linkedin.com/shareArticle?mini=true&url=" + encodeURIComponent(document.location.href) + "&title=" + encodeURIComponent(document.title) + "&source=" + currenturl;
下面是写的一个分享的方法,直接用点击事件调用就行啦
/**
* 分享
* @param type 分享类型 1:twitter、2:facebook、3:linkedin
*/
function share(type) {
//首先 参数准备
let url = "";
//获取当前url以及title
let currentUrl = encodeURIComponent(document.location.href);
let currentTitle = encodeURIComponent(document.title);
//跳转打开新页面设置
let param = "";
//选择你要使用的分享
if (type == 1) {
url = "http://twitter.com/intent/tweet?url=" + currentUrl + " " + currentTitle;
param = "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=600, height=450,top=100,left=350";
} else if (type == 2) {
url = "http://www.facebook.com/sharer.php?u=" + currentUrl + '&t=' + currentTitle;
param = "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=600, height=450,top=100,left=350";
} else if (type == 3) {
url = "http://www.linkedin.com/shareArticle?mini=true&url=" + currentUrl + '&title=' + currentTitle + '&source=' + currentUrl;
param = "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=600, height=450,top=100,left=350";
}
window.open(url, "_blank", param);
}