1. 程式人生 > >JavaScript,簡單的社交圈分享

JavaScript,簡單的社交圈分享

mstr 微信 templates connect esc col function ava des

var share_templates = {
    //qzone-param    url, title, desc, summary, site
    qzone: ‘http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?‘,
    //qq-param    url, title, desc, pics, source
    qq: ‘http://connect.qq.com/widget/shareqq/index.html?‘,
    //tencent-param    url, title, pic
    tencent: ‘http://share.v.t.qq.com/index.php?c=share&a=index&‘,
    
//weibo-param url, title, pic, appkey weibo: ‘http://service.weibo.com/share/share.php?‘, //douban-param href, name, text, image douban: ‘http://shuo.douban.com/!service/share?starid=0&aid=0&style=11&‘, //linkedin-param url, title, summary, source linkedin: ‘http://www.linkedin.com/shareArticle?mini=true&ro=true&armin=armin&‘,
//facebook-param u facebook: ‘https://www.facebook.com/sharer/sharer.php?‘, //twitter-param text, url, via twitter: ‘https://twitter.com/intent/tweet?‘, //google-param url google: ‘https://plus.google.com/share?‘, //line url line: ‘https://lineit.line.me/share/ui?‘ }; var share = function
(sitename, param){ var paramString = share_templates[sitename] || share_templates.sitename; if(paramString.trim() != ‘‘){ for (var key in param) { if (param.hasOwnProperty(key)) { paramString = paramString + key + ‘=‘ + encodeURIComponent(param[key]) + ‘&‘; } } window.open(paramString,‘_blank‘); } }

沒有微信的。github上有個不錯的項目 https://github.com/overtrue/share.js 就是有點太完美了,如果需求比較簡單,可以直接用上面的代碼。

順帶一提,分享連接時 param[key] 最好是Unicode編碼。

JavaScript,簡單的社交圈分享