我们经常会有分享到大网站的需求来满足用户吸引。常用的有分享到新浪/腾讯/人人网等。那么如何实现这些分享呢?今天就来探究一下,,首先了解一下第三方登录。

1.常用的第三方登陆

我们想要在自己的网站上提供第三方平台登录,类似这样的:

这样的需求我们是要到腾讯QQ或者新浪开发者平台申请appkey权限才能接入的第三方平台的用户数据,获取用户的昵称,头像,性别,id等信息,可以写入数据库作为本站登录的一种方式。或者用百度的开放平台,已经集成了。具体这方面的操作还是有点复杂,需要一定的耐心,大家可以到相应的平台看API文档学习。

2.常用的分享链接

现在的营销手段中,经常会让用户参与活动并分享给好友才能获得奖励。这样的情况下就需要一个分享功能了,现在最常用的就是分享到新浪微博,微信等。那么我们该如何完成呢?

方式一:通过插件代码实现

比如jiaThis插件,它提供了形式多样的功能强大的分享。

<!-- JiaThis Button BEGIN -->
<div class="jiathis_style_32x32"><a class="jiathis_button_qzone"></a><a class="jiathis_button_tsina"></a><a class="jiathis_button_tqq"></a><a class="jiathis_button_weixin"></a><a class="jiathis_button_renren"></a><a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a><a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

只要引入jia.js这个文件,通过相应的类名,即可实现分享。对于样式还提供可配置操作。

总结:通过这种方式分享,功能齐全,但是不稳定,例如我用的时候jia.js文件报错,导致请求浪费好多时间。而且功能强大有时候并不全是好事,我们只需要新浪分享的时候,加载这样一个插件未免大材小用。其实新浪微博还提供了简洁的分享方式。

方式二:百度分享

只需复制以下代码,即可获取如下图所示常见分享效果。

<div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a><a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a></div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdPic":"","bdStyle":"0","bdSize":"16"},"share":{},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"},"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>

方式三:通过链接分享(推荐)

$(".weib-share").click(function(){var shareContent="我的速度打败了全国"+$("#rank").html()+"的人,@华企商学院,快快赐我一份大奖吧,不服来战!!!";var shareText = 'http://v.t.sina.com.cn/share/share.php?url=http://www.shao-ming.com&title=' + shareContent;$(this).attr("href",shareText);});});

其中.weib-share是一个a元素。

这是我自己写的,其实灵感是来自下面的内容。

网页常用分享代码:1、新浪微博
<a href="http://v.t.sina.com.cn/share/share.php?url=http://www.shao-ming.com&title='分享内容'" target="_blank">新浪微博</a>2、腾讯微博
<a href="http://v.t.qq.com/share/share.php?url=http://www.shao-ming.com&title='分享内容'" target="_blank">腾讯微博</a>3、开心网
<a href="javascript:window.open('http://www.kaixin001.com/repaste/share.php?rtitle='+encodeURIComponent(document.title)+'&rurl='+encodeURIComponent(document.location.href)+'&rcontent=');void(0)">开心网</a>
或者用
<a href="http://www.kaixin001.com/repaste/share.php?rurl=http://www.shao-ming.com&rcontent=http://www.baidu.com&rtitle=kaixin" target="_blank">开心网</a>4、豆瓣网
<a href="javascript:window.open('http://www.douban.com/recommend/?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title));void(0)">豆瓣</a>或者用
<a href="http://www.douban.com/recommend/?url=http://www.shao-ming.com&title=douban" target="_blank">豆瓣</a>5、人人网
<a href="javascript:window.open('http://share.renren.com/share/buttonshare.do?link='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title));void(0)">人人网</a>
或者用
<a href="http://share.renren.com/share/buttonshare.do?link=http://www.shao-ming.com" target="_blank">人人网</a>6、百度贴吧
<a href="http://tieba.baidu.com/f/commit/share/openShareApi?url=http://www.shao-ming.com&title=hello&desc=&pic=" target="_blank">百度贴吧</a>7、QQ好友
<a href="http://connect.qq.com/widget/shareqq/index.html?title=qqhaoyou&url=http://www.shao-ming.com&desc=还不错哦&pics=&site=优酷" target="_blank">QQ好友</a>8、QQ空间
<a href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=http://www.shao-ming.com" target="_blank">QQ空间</a>9、腾讯朋友
<a href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?to=pengyou&url=http://www.shao-ming.com" target="_blank">腾讯朋友</a>10、百度收藏
<a href="javascript:window.open('http://cang.baidu.com/do/add?it='+encodeURIComponent(document.title.substring(0,76))+'&iu='+encodeURIComponent(location.href)+'&fr=ien#nw=1','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); void 0">百度搜藏</a>11、优酷空间
<a href="http://i.youku.com/u/share/?url=http://www.shao-ming.com&content='分享内容'" target="_blank">优酷空间</a>12、搜狐微博
<a href="http://t.sohu.com/third/post.jsp?content=utf-8&url=http://www.shao-ming.com&title=souhu" target="_blank">搜狐微博</a>13、MSN
<a href="http://profile.live.com/badge/?url=http://www.shao-ming.com&Title=msn" target="_blank">MSN</a>14、猫扑
<a href="http://tt.mop.com/share/shareV.jsp?title=moptietie&pageUrl=http://www.shao-ming.com" target="_blank">MOP贴贴</a>15、网易微博
<a href="http://t.163.com/article/user/checkLogin.do?link=http://www.shao-ming.com" target="_blank">网易微博</a>16、QQ书签<a href="javascript:window.open('http://shuqian.qq.com/post?from=3&title='+encodeURIComponent(document.title)+'&uri='+encodeURIComponent(document.location.href)+'&jumpback=2&noui=1','favit','width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes');void(0)">QQ书签</a>17、GOOGLE书签:
<a href="javascript:window.open('http://www.google.com/bookmarks/mark?op=add&bkmk='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title));void(0)">Google</a>18、Twitter
<a href="javascript:window.open('http://twitter.com/home?status='+encodeURIComponent(document.location.href)+' '+encodeURIComponent(document.title));void(0)">Twitter</a>19、Facebook
<a class="fav_facebook" rel="nofollow" href="javascript:window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(document.location.href)+'&t='+encodeURIComponent(document.title));void(0)">Facebook</a>20、Delicious书签:<a href="javascript:window.open('http://del.icio.us/post?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title)+'&notes=');void(0)">Delicious</a>

还可以自己封装一下方法:

var ShareTip = function(){}
//分享到腾讯微博
ShareTip.prototype.sharetoqq=function(content,url,picurl)
{  var shareqqstring='http://v.t.qq.com/share/share.php?title='+content+'&url='+url+'&pic='+picurl;  window.open(shareqqstring,'newwindow','height=100,width=100,top=100,left=100');
}
//分享到新浪微博
ShareTip.prototype.sharetosina=function(title,url,picurl)
{  var sharesinastring='http://v.t.sina.com.cn/share/share.php?title='+title+'&url='+url+'&content=utf-8&sourceUrl='+url+'&pic='+picurl;  window.open(sharesinastring,'newwindow','height=400,width=400,top=100,left=100');
}
//分享到QQ空间
ShareTip.prototype.sharetoqqzone=function(title,url,picurl)
{  var shareqqzonestring='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?summary='+title+'&url='+url+'&pics='+picurl;  window.open(shareqqzonestring,'newwindow','height=400,width=400,top=100,left=100');
}  

以上的函数分别具有三个参数,内容,网址,以及 图片,也就是我们想要分享的内容,测试代码如下(我们可以写在一个按钮的单击事件里,关于按钮的长相,这个自己定义)

var share1=new ShareTip();
share1.sharetoqqzone("这是一本关于地图故事的集锦,以一本书的形式来展示地图故事,我们可以使用鼠标拖动来翻页,或者点击翻页按钮,点击 马上体验,可以体验故事,同时在触屏上也有很好的体验效果奥,地图故事,尽在书中,赶快体验吧,建议使用对 HTML5支持较好的浏览器","http://tm.arcgisonline.cn:8038/App101/MapstoryBook/Default.html","http://tm.arcgisonline.cn:8038/App101/MapstoryBook/css/Img/ShareBook.jpg");

好了,希望对你有用。

分享到新浪/腾讯/人人等相关推荐

  1. HQChart实战教程41 -新浪+腾讯A股数据源对接 - uniapp版本 (源码付费)

    HQChart实战教程41 -新浪+腾讯A股数据源对接 - uniapp版本 数据源 支持周期 平台支持 demo安卓apk下载 源码售价 580元 效果截图 HQChart代码地址 数据源 使用公开 ...

  2. HBuilder webApp开发(七)微信/QQ/新浪/腾讯微博分享

    HBuilder是支持微信分享(好友和朋友圈),QQ分享,新浪微博和腾讯微博分享. 但是在使用的过程中,官方给的文档似乎很坑爹. <分享插件配置> <分享插件开发指南> 都是2 ...

  3. 《浪潮之巅》作者吴军老师新浪/腾讯“微访谈”实录

    [新浪"银联培训中心UP微访谈"] 时间:2011-9-23 21:30~22:40 新浪网友@刘江CE:吴老师怎么看下一十年Google.Apple.Facebook.Amazo ...

  4. python新浪股票接口 2019_用python爬虫进行新浪腾讯股票数据采集

    今天带给大家的是从新浪和腾讯爬取股票数据,主要是因为新浪和腾讯的股票数据存储在js中,不需要再重新解析网页源码方便很多. 今天我们要实现的股票爬取设计内容丰富,包括: 1.一个股票数据(沪深)爬虫和选 ...

  5. 新型冠状病毒全国疫情新浪腾讯网易API接口json

    一.新浪提供的接口地址: https://interface.sina.cn/news/wap/fymap2020_data.d.json 二.163提供的接口地址: 官方展示: https://ne ...

  6. 新浪腾讯微博互刷互粉工具-网页版

    其实早些年,应该算是前年吧.就已经注册了新浪微博,然后腾讯微博出来了就又注册了腾讯微博,不过,推特还真没注册过,当我知道的时候就已经需要爬墙了,人矮,懒得爬了! 那时候,腾讯我记得我发过好几期的邀请码 ...

  7. php获取视频信息,支持优酷土豆新浪腾讯等多家网站

    video.php类 <?php /** * 解析 视频信息 类 * * 支持 优酷, 土豆 酷6 56 新浪 qq播客 乐视 乐视 **/class class_video{// 超时时间va ...

  8. 新浪,腾讯原生态SDK分享

    主要有两个界面,一个是新浪微博,腾讯微博的分享按钮,一个是他们的绑定情况(其实就是是否授权).点击微博分享中新浪或腾讯按钮,就进行相应的授权(若没授权),显示微博内容,而后发布微博.设置界面中的绑定, ...

  9. java 新浪短链接_新浪短链接/腾讯短链接的API接口分享(含调用代码)

    最新好多朋友需要使用腾讯/新浪的官方短连接api接口,但是自己无法获取,或者说现有的API接口不支持现在的高频率调用,今天我就分享几个新浪/腾讯短域名的API接口给大家使用! 短链接他的目的就是将冗长 ...

最新文章

  1. 虚拟机VMware12下安装windows7 x64系统使用教程
  2. Android 如何有效的解决内存泄漏的问题
  3. JavaScript-概述
  4. shell脚本 猜数字游戏并计数比较次数
  5. java日历查询代码,查询日历,万年历查询,日历格式JAVA原代码
  6. [和管子对话] 2 2007-4-6/抽象类和接口的谁是谁非
  7. 指纹和人脸识别 AI 总结
  8. win7企业版怎么都激活不了,看这里
  9. Layout inflation的正确使用
  10. 网络计算机怎么使用,如何让电脑使用ipv6地址?一文了解清楚
  11. 基于python的异方差检验_【Python】统计科学之讲讲异方差的检验
  12. springboot系列(二十七):如何实现word携带图片导出?这你得会|超级详细,建议收藏
  13. CSDN怎么改变字体颜色
  14. 揭示未来方向:2018中国TMT行业“领秀榜”盛典直击
  15. 世界上第一个微处理器真的是Intel 4004吗?其实这是个很复杂的故事…
  16. 基于3dmax及Unity的虚拟博物展览馆
  17. 《奇特的一生》——致敬时间的神
  18. 查询mysql 的内存使用_mysql查看内存使用情况
  19. matlab因子载荷矩阵正交旋转,因素分析中的矩阵旋转
  20. 软件工程 常见术语 中英对照

热门文章

  1. 华为官宣进军ERP的背后透露出哪些信息,华为会成功么
  2. MS CASTEP模块的计算原理和功能
  3. Linux解压缩的几种用法
  4. Oracle 隐藏参数:_undo_autotune
  5. 联想手机android系统耗电,乐省电让手机电池更有计划性_联想 A820t_手机Android频道-中关村在线...
  6. 设函数f(x)与g(x)在点x0连续,证明函数φ(x)=max{f(x),g(x)},ψ(x)=min{f(x),g(x)}在x0也连续
  7. 【报告分享】2020中国跨境电商市场发展报告-CBEC(附下载)
  8. 判断GPS坐标是否在中国
  9. 如何获取各城市POI总量?
  10. java全网最为优质的技术交流微信群,qq群,工作、交流、学习亦可