//1 分享QQ好友
function qq(title,url,pic) { var p = { url: 'http://test.qicheyitiao.com',/*獲取URL,可加上來自分享到QQ標識,方便統計*/ desc: '來自汽車氪的分享', /*分享理由(風格應模擬用戶對話),支持多分享語隨機展現(使用|分隔)*/ title : title,/*分享標題(可選)*/ summary : title,/*分享描述(可選)*/ pics : pic,/*分享圖片(可選)*/ flash : '', /*視頻地址(可選)*/ //commonClient : true, /*客戶端嵌入標志*/ site: '汽車氪'/*分享來源 (可選) ,如:QQ分享*/ }; var s = []; for (var i in p) { s.push(i + '=' + encodeURIComponent(p[i] || '')); } var target_url = "http://connect.qq.com/widget/shareqq/iframe_index.html?" + s.join('&') ; window.open(target_url, 'qq', 'height=520, width=720'); }
//2 分享到QQ空間
function qZone(title,pic){ var p = { url: '', showcount: '1',/*是否顯示分享總數,顯示:'1',不顯示:'0' */ desc: '這篇文章不錯,分享一下~~',/*默認分享理由(可選)*/ summary: '',/*分享摘要(可選)*/ title: title,/*分享標題(可選)*/ site: '汽車氪',/*分享來源 如:騰訊網(可選)summary*/ pics: pic, /*分享圖片的路徑(可選)*/ style: '101', width: 199, height: 30 }; var s = []; for (var i in p) { s.push(i + '=' + encodeURIComponent(p[i] || '')); } var target_url = "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?"+s.join('&'); window.open(target_url, 'qZone', 'height=430, width=400'); }
3 //微信分享
function weixin(){ var target_url = "http://qr.liantu.com/api.php?text=http://test.qicheyitiao.com"; window.open(target_url, 'weixin', 'height=320, width=320'); } // 分享新浪微博 function sinaWeiBo(title,url,pic){ var param = { url:url, type:'3', count:'1', /** 是否顯示分享數,1顯示(可選)*/ appkey:'汽車氪', /** 您申請的應用appkey,顯示分享來源(可選)*/ title:title, /** 分享的文字內容(可選,默認為所在頁面的title)*/ pic:pic, /**分享圖片的路徑(可選)*/ ralateUid:'', /**關聯用戶的UID,分享微博會@該用戶(可選)*/ rnd:new Date().valueOf() } var temp = []; for( var p in param ){ temp.push(p + '=' +encodeURIComponent( param[p ] || '' ) ) } var target_url = "http://service.weibo.com/share/share.php?"+temp.join('&'); window.open(target_url, 'sinaweibo', 'height=430, width=400'); }
注意 :記住了QQ分享的的url 如果是localhost是不行的。
本文轉自:https://blog.csdn.net/csdnwangjianxin/article/details/51799235