Javascript将内容分享到各大社交平台网站的代码总结

 
更多

最近频繁的使用将内容分享到各大社交平台的功能,因此对该功能做了一下小小的总结,主要是使用Javascript将内容分享到各大社交平台网站进行归纳整理了一下,小结要点如下,希望能帮到有需要的朋友。

关键性的代码(Javascript):

function sharePlugin(name,img,title){
	var purl=encodeURIComponent(document.location.href);
	switch(name){
		case 'sina':
			var url='http://service.t.sina.com.cn/share/share.php?url='+purl+'&appkey=2858164115&title='+encodeURIComponent(""+title)+'&pic='+encodeURIComponent(img)+'&ralateUid=&searchPic=false';//注意这个地方使用了一个appkey,分享到新浪的时候会有一个分享来源,其中的分享来源就取决于这个appkey,你可以根据需要改成自己的appkey
			window.open(url);
		break;
		case 'tqq':
			var url='http://v.t.qq.com/share/share.php?title='+encodeURIComponent(""+title)+'&url='+purl+'&appkey='+encodeURI("8675d8896e054316bc69755118dea3c9")+'&site='+purl+'&pic='+img;
			window.open( url,'转播到腾讯微博','width=700,height=680,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,location=yes,resizable=no,status=no' );
		break;
		case 'kaixin':
			var url='http://www.kaixin001.com/repaste/share.php?rurl='+purl+'&rcontent='+encodeURIComponent(""+title)+'&rtitle='+encodeURIComponent("欣和食与家");
			window.open(url);
		break;
		case 'renren':
			var url='http://share.renren.com/share/buttonshare.do?link='+purl+'&title='+encodeURIComponent(""+title);
			window.open(url);
		break;
		case 'douban':
			var url='http://www.douban.com/recommend/?url='+purl+'&title='+encodeURIComponent(""+title);
			window.open(url);
		break;
		case 'qzone':
			var url='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(""+title)+'&pics='+img;
			window.open(url);
		break;
	}
}

以上代码经净化处理后:

function sharePlugin(name,img,title){var purl=encodeURIComponent(document.location.href);switch(name){case'sina':var url='http://service.t.sina.com.cn/share/share.php?url='+purl+'&appkey=2858164115&title='+encodeURIComponent(""+title)+'&pic='+encodeURIComponent(img)+'&ralateUid=&searchPic=false';window.open(url);break;case'tqq':var url='http://v.t.qq.com/share/share.php?title='+encodeURIComponent(""+title)+'&url='+purl+'&appkey='+encodeURI("8675d8896e054316bc69755118dea3c9")+'&site='+purl+'&pic='+img;window.open(url,'转播到腾讯微博','width=700,height=680,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,location=yes,resizable=no,status=no');break;case'kaixin':var url='http://www.kaixin001.com/repaste/share.php?rurl='+purl+'&rcontent='+encodeURIComponent(""+title)+'&rtitle='+encodeURIComponent("欣和食与家");window.open(url);break;case'renren':var url='http://share.renren.com/share/buttonshare.do?link='+purl+'&title='+encodeURIComponent(""+title);window.open(url);break;case'douban':var url='http://www.douban.com/recommend/?url='+purl+'&title='+encodeURIComponent(""+title);window.open(url);break;case'qzone':var url='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(""+title)+'&pics='+img;window.open(url);break}}

具体的使用方法如下(完整代码):

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>www.phpernote.com</title>
<script language="javascript">
function sharePlugin(name,img,title){var purl=encodeURIComponent(document.location.href);switch(name){case'sina':var url='http://service.t.sina.com.cn/share/share.php?url='+purl+'&appkey=2858164115&title='+encodeURIComponent(""+title)+'&pic='+encodeURIComponent(img)+'&ralateUid=&searchPic=false';window.open(url);break;case'tqq':var url='http://v.t.qq.com/share/share.php?title='+encodeURIComponent(""+title)+'&url='+purl+'&appkey='+encodeURI("8675d8896e054316bc69755118dea3c9")+'&site='+purl+'&pic='+img;window.open(url,'转播到腾讯微博','width=700,height=680,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,location=yes,resizable=no,status=no');break;case'kaixin':var url='http://www.kaixin001.com/repaste/share.php?rurl='+purl+'&rcontent='+encodeURIComponent(""+title)+'&rtitle='+encodeURIComponent("欣和食与家");window.open(url);break;case'renren':var url='http://share.renren.com/share/buttonshare.do?link='+purl+'&title='+encodeURIComponent(""+title);window.open(url);break;case'douban':var url='http://www.douban.com/recommend/?url='+purl+'&title='+encodeURIComponent(""+title);window.open(url);break;case'qzone':var url='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(""+title)+'&pics='+img;window.open(url);break}}
</script>
</head>
<body>
<a href="#" onclick="sharePlugin('renren','http://www.phpernote.com/images/logo.gif','http://www.phpernote.com')">分享到人人网</a>
<br />
<a href="#" onclick="sharePlugin('tqq','http://www.phpernote.com/images/logo.gif','http://www.phpernote.com')">分享到腾讯微博</a>
<br />
<a href="#" onclick="sharePlugin('sina','http://www.phpernote.com/images/logo.gif','http://www.phpernote.com')">分享到新浪微博</a>
<br />
<a href="#" onclick="sharePlugin('kaixin','http://www.phpernote.com/images/logo.gif','http://www.phpernote.com')">分享到开心网</a>
</body>
</html>
打赏

本文固定链接: https://www.cxy163.net/archives/4633 | 绝缘体

该日志由 绝缘体.. 于 2013年05月23日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: Javascript将内容分享到各大社交平台网站的代码总结 | 绝缘体
关键字: , , , ,

Javascript将内容分享到各大社交平台网站的代码总结:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter