Facebook、Twitter、LinkedIn分享

标题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);
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值