常德德雅网站建设

NEWS新闻

最近正在折腾...
Recently is to do ...

德雅网络针对js 几个网站的分享链接方法?

UPTATED:2014/12/18 19:45:42 | 分类:js特效

在前辈的基础上总结了下一些网站分享的代码,虽然网上有些现成的分享插件,但是我加到页面上会有样式问题,所以自己总结了下。

// JavaScript Document

function HTMLEncode(html) {
var temp = document.createElement("div"); (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
var output = temp.innerHTML;
temp = null;
return output
}
function HTMLDecode(text) {
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output
}


/**
 **分享方法
 */
function share(type) {
var link = '';
var pics = new Array();
switch (type) {
 //新浪
case 'sina':
link = 'http://v.t.sina.com.cn/share/share.php?&url={url}&title={title}&content=gb2312';
break;
//qq微博
case 'qqt':
link = 'http://v.t.qq.com/share/share.php?title={title}&url={url}&pic={pic:|}';
break;
//人人网
case 'renren':
link = 'http://share.renren.com/share/buttonshare.do?link={url}&title={title}';
break;
//qq空间
case 'qzone':
link = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={url}&title={title}';
break;
//豆瓣
case 'douban':
link = "http://www.douban.com/recommend/?url={url}&title";
break;
//腾讯朋友
case 'pengyou':
link = "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?to=pengyou&url={url}&title={title}";
break;
//msn
case 'msn':
link = "http://profile.live.com/P.mvc#!/badge?url={url}&title={title}&pic={pic:|}";
break;
//猫扑
case 'mop':
link = "http://tt.mop.com/share/shareV.jsp?pageUrl={url}&title={title}";
break;
}
    
$('img').each(function(i, n) {
pics.push(n.src);
});

link = link.replace('{title}', encodeURIComponent(HTMLDecode(document.getElementsByTagName('title')[0].innerHTML)));
link = link.replace('{url}', encodeURIComponent(window.location.href));
link = link.replace('{pic:|}', pics.join('|'));
window.open(link);
}




评论加载中...
内容:
评论者: 验证码: