分享功能初步测试,title为当前页面的title。 其他详见注释!!!

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8;">
<title>分享代码测试</title>
<meta name="author" content="rainna" />
<meta name="keywords" content="rainna's js lib" />
<meta name="description" content="js" />
<style>
*{margin:0;padding:0;}
img{border:0 none;}
body{background:#eee;}
.m-box{width:800px;margin:0 auto;padding:20px;background:#fff;}
.m-box p{margin:0 0 10px;}
.m-box .icn a{display:block;width:55px;height:35px;background:url('http://l.bst.126.net/rsc/img/weibo.png?035') no-repeat;}
.m-box .icn .wb1{background-position:10px -216px;}
.m-box .icn .wb2{background-position:-190px -216px;}
.m-box .icn .wb3{background:url(http://l.bst.126.net/rsc/img/postshare/tieba24.png) 15px 0 no-repeat;}
.m-box .icn .wb4{background-position:-88px -215px;}
.m-box .icn .wb5{background-position:-138px -216px;}
.m-box .icn .wb6{background-position:-245px -216px;}
.m-box .icn .wb7{background-position:-300px -216px;}
.m-box .icn .wb8{background-position:-355px -216px;}
.m-box .icn .wb9{background-position:-415px -215px;}
</style>
</head>
<body>
<div class="m-box">
<p>分享到微信,易信:</p>
<div class="icn"><img width="200" src="https://qr.api.cli.im/qr?data=http%253A%252F%252Fwww.cnblogs.com%252FCooLLYP%252F&level=H&transparent=false&bgcolor=%23ffffff&forecolor=%23000000&blockpixel=12&marginblock=1&logourl=&size=280&kid=cliim&key=6b3febe84f9780fb193f9d8f9d189e4f" /></div>
</div>
<div class="m-box">
<p>分享到新浪微博:<a href="http://open.weibo.com/wiki/ShareCode" target="_blank">http://open.weibo.com/wiki/ShareCode</a></p>
<div class="icn"><a href="#" class="wb1" onclick="shareToSinaWB(event)"></a></div>
</div>
<div class="m-box">
<p>分享到QQ空间:<a href="http://connect.qq.com/intro/share/" target="_blank">http://connect.qq.com/intro/share/</a></p>
<div class="icn"><a href="#" class="wb2" onclick="shareToQzone(event)"></a></div>
</div>
<div class="m-box">
<p>分享到百度贴吧:<a href="http://share.baidu.com/code/advance" target="_blank">http://share.baidu.com/code/advance</a></p>
<div class="icn"><a href="#" class="wb3" onclick="shareToTieba(event)"></a></div>
</div>
<div class="m-box">
<p>分享到豆瓣:</p>
<div class="icn"><a href="#" class="wb4" onclick="shareToDouban(event)"></a></div>
</div>
<div class="m-box">
<p>分享到腾迅微博:<a href="http://dev.t.qq.com/websites/share/" target="_blank">http://dev.t.qq.com/websites/share/</a></p>
<div class="icn"><a href="#" class="wb5" onclick="shareToQQwb(event)"></a></div>
</div>
<div class="m-box">
<p>分享到开心网:<a href="http://open.kaixin001.com/document.php?type=records#code" target="_blank">http://open.kaixin001.com/document.php?type=records#code</a></p>
<div class="icn"><a href="#" class="wb7" onclick="shareToKaixin(event)"></a></div>
</div>
<div class="m-box">
<p>分享到facebook:</p>
<div class="icn"><a href="#" class="wb8" onclick="shareToFacebook(event)"></a></div>
</div>
<div class="m-box">
<p>分享到Twitter:</p>
<div class="icn"><a href="#" class="wb9" onclick="shareToTwitter(event)"></a></div>
</div>
<script>
var _title,_source,_sourceUrl,_pic,_showcount,_desc,_summary,_site,
_width = 600,
_height = 600,
_top = (screen.height-_height)/2,
_left = (screen.width-_width)/2,
_url = 'http://www.cnblogs.com/CooLLYP/',
_pic = 'https://pic.cnblogs.com/avatar/1035330/20160929170744.png';
//分享到新浪微博
function shareToSinaWB(event){
event.preventDefault();
var _shareUrl = 'http://v.t.sina.com.cn/share/share.php?&appkey=895033136'; //真实的appkey,必选参数
_shareUrl += '&url='+ encodeURIComponent(_url||document.location); //参数url设置分享的内容链接|默认当前页location,可选参数
_shareUrl += '&title=' + encodeURIComponent(_title||document.title); //参数title设置分享的标题|默认当前页标题,可选参数
_shareUrl += '&source=' + encodeURIComponent(_source||'');
_shareUrl += '&sourceUrl=' + encodeURIComponent(_sourceUrl||'');
_shareUrl += '&content=' + 'utf-8'; //参数content设置页面编码gb2312|utf-8,可选参数
_shareUrl += '&pic=' + encodeURIComponent(_pic||''); //参数pic设置图片链接|默认为空,可选参数
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',top='+_top+',left='+_left+',toolbar=no,menubar=no,scrollbars=no, resizable=1,location=no,status=0');
}
//分享到QQ空间
function shareToQzone(event){
event.preventDefault();
var _shareUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?';
_shareUrl += 'url=' + encodeURIComponent(_url||document.location); //参数url设置分享的内容链接|默认当前页location
_shareUrl += '&showcount=' + _showcount||0; //参数showcount是否显示分享总数,显示:'1',不显示:'0',默认不显示
_shareUrl += '&desc=' + encodeURIComponent(_desc||'分享的描述'); //参数desc设置分享的描述,可选参数
_shareUrl += '&summary=' + encodeURIComponent(_summary||'分享摘要'); //参数summary设置分享摘要,可选参数
_shareUrl += '&title=' + encodeURIComponent(_title||document.title); //参数title设置分享标题,可选参数
_shareUrl += '&site=' + encodeURIComponent(_site||''); //参数site设置分享来源,可选参数
_shareUrl += '&pics=' + encodeURIComponent(_pic||''); //参数pics设置分享图片的路径,多张图片以"|"隔开,可选参数
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',top='+_top+',left='+_left+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
}
//分享到百度贴吧
function shareToTieba(event){
event.preventDefault();
var _shareUrl = 'http://tieba.baidu.com/f/commit/share/openShareApi?';
_shareUrl += 'title=' + encodeURIComponent(_title||document.title); //分享的标题
_shareUrl += '&url=' + encodeURIComponent(_url||document.location); //分享的链接
_shareUrl += '&pic=' + encodeURIComponent(_pic||''); //分享的图片
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
}
//分享到豆瓣
function shareToDouban(event){
event.preventDefault();
var _shareUrl = 'http://shuo.douban.com/!service/share?';
_shareUrl += 'href=' + encodeURIComponent(_url||location.href); //分享的链接
_shareUrl += '&name=' + encodeURIComponent(_title||document.title); //分享的标题
_shareUrl += '&image=' + encodeURIComponent(_pic||''); //分享的图片
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
}
//分享到腾迅微博
function shareToQQwb(event){
event.preventDefault();
var _shareUrl = 'http://v.t.qq.com/share/share.php?';
_shareUrl += 'title=' + encodeURIComponent(_title||document.title); //分享的标题
_shareUrl += '&url=' + encodeURIComponent(_url||location.href); //分享的链接
_shareUrl += '&appkey=5bd32d6f1dff4725ba40338b233ff155'; //在腾迅微博平台创建应用获取微博AppKey
_shareUrl += '&site=' + encodeURIComponent(_site||''); //分享来源
_shareUrl += '&pic=' + encodeURIComponent(_pic||''); //分享的图片,如果是多张图片,则定义var _pic='图片url1|图片url2|图片url3....'
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
}
//分享到开心网
function shareToKaixin(event){
event.preventDefault();
var _shareUrl = 'http://www.kaixin001.com/rest/records.php?';
_shareUrl += 'url=' + encodeURIComponent(_url||location.href); //分享的链接
_shareUrl += '&content=' + encodeURIComponent('分享的文字'); //需要分享的文字,当文字为空时,自动抓取分享网址的title
_shareUrl += '&pic=' + encodeURIComponent(_pic||''); //分享的图片,多个使用半角逗号分隔
_shareUrl += '&showcount=0'; //是否显示分享数,显示:'1',不显示:'0'
_shareUrl += '&style=11'; //显示的样式,必选参数
_shareUrl += '&aid=' + encodeURIComponent(_site||''); //显示分享来源
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
}
function shareToKaixin2(event){
event.preventDefault();
var _shareUrl = 'http://www.kaixin001.com/repaste/share.php?';
_shareUrl += 'rtitle=' + encodeURIComponent(_title||document.title); //分享的标题
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
}
//分享到facebook
function shareToFacebook(event){
event.preventDefault();
var _shareUrl = 'http://www.facebook.com/sharer/sharer.php?';
_shareUrl += 'u=' + encodeURIComponent(_url||location.href); //分享的链接
_shareUrl += '&t=' + encodeURIComponent(_title||document.title); //分享的标题
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
}
//分享到Twitter
function shareToTwitter(event){
event.preventDefault();
var _shareUrl = 'http://twitter.com/intent/tweet?';
_shareUrl += 'url=' + encodeURIComponent(_url||location.href); //分享的链接
_shareUrl += '&text=' + encodeURIComponent(_title||document.title); //分享的标题
window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
}
</script>
</body>
</html>

js 实现分享功能的更多相关文章

  1. js前端分享功能

    直接添加网页分享代码就可以了.实现方法如下:1.打开百度分享:http://share.baidu.com.2.点击“代码获取”.3.进行个性化设置.

  2. 微信JS分享功能--微信JS系列文章(二)

    概述 在上一篇文章微信JS初始化-- 微信JS系列文章(一)中已经介绍了微信JS初始化的相关工作,接下来本文继续就微信JS的分享功能进行描述,供大家参考. 代码 $(document).ready(f ...

  3. js分享功能

    引用JiaThis的分享功能: 直接在想要放置分享功能的地方加上如下代码即可: <!-- JiaThis Button BEGIN --> <div class="jiat ...

  4. js分享功能(微信,QQ,微博,空间,豆瓣等)

    日常编程中,我们可能会碰到项目中的分享功能,各大平台都有分享接口和文档说明,当然也有一些一键分享插件,例如:sosh,iShare.js等等 但有些同学不想引用插件,那么我整理了一些常用的分享至平台功 ...

  5. php框架tp3.2.3和js写的微信分享功能心得,分享的标题内容图片自定义

    https://blog.csdn.net/weixin_42231483/article/details/81585322 最近用PHP的tp3.2.3框架和js写的微信分享功能心得,分享的标题内容 ...

  6. 页面分享功能,分享好友、朋友圈判断,用share_type做标记 这里用的是jweixin-1.3.2.js

    这里用的是jweixin-1.3.2.js trigger: function (res) { //判断分享的状态,好友.朋友圈 localStorage.setItem("share_ty ...

  7. js 微信分享

    一. //js接口 var shareme; var urls = window.location.href; if(isWeiXin()){   var weifileref=document.cr ...

  8. 微信JS-SDK实际分享功能

    为了净化网络,整顿诱导分享及诱导关注行为,微信于2014年12月30日发布了<微信公众平台关于整顿诱导分享及诱导关注行为的公告>,微信平台开发者发现,原有的微信分享功能不能用了,在ipho ...

  9. js快速分享代码

    这是一款简单易用的文章分享工具,您只需将下面的html代码拷贝到模板中就可以实现文章快速分享功能.如果您想分享你的博客.个人网站或者企业网站等等,下面是两款不错的分享工具,值得拥有! 1. <d ...

随机推荐

  1. 前端(三):JavaScript基础

    JavaScript是一种属于网络的脚本语言,常用来为网页添加各式各样的动态功能,是一种动态类型.弱类型.基于原型的语言.它包括三个部分:ECMAScript.BOM和DOM.ECMAScript描述 ...

  2. android 动态库死机调试方法 .

    原地址:http://blog.csdn.net/andyhuabing/article/details/7074979 这两种方法都不是我发明了,都是网上一些高手公共出来的调试方法,无奈找不到出处的 ...

  3. C Primer Plus note9

    undefined reference to `WinMain@16'| 运行程式的时候出现了这样的错误,而且编译器也没有提示是哪一行出错: 经过百度搜索,发现了问题所在: 上面的图中main()函数 ...

  4. tmux使用技巧

    1.tmux 进入tmux 2.在tmux中 按ctrl+b 表示要进行tmux操作了. 3. c -> create a session 4. ","  -> ren ...

  5. Cocos2d-js 开发记录:骨骼动画载入

    不得不说cocos2d-js的文档实在是少,骨骼动画的载入和C++版本的好像还有些不同不能直接依样画葫芦. 一个由cocos studio编辑生成的骨骼动画一般会包含如下几个文件: .ExportJs ...

  6. Git Bash Here常用命令以及使用步骤

    1.首先,要clone项目代码: git clone 链接地址 2.更新代码: git pull 3.添加修改过的文件.文件夹: git add 修改过的文件,文件夹 4.提交并注释: git com ...

  7. Web前端面试指导(十九):CSS样式-如何清除元素浮动?

    题目点评 本题属于比较常问的题目,也是在网页设计中经常遇到的问题,面试官希望通过这样的面试题来了解你对网页设计的基本功底,如果这样的题目答不出来,必会让面试官大失所望,面试成功的概率是非常小的. 答题 ...

  8. console的一些方法

    原文参考http://mp.weixin.qq.com/s?__biz=MzU3MDA0NTMzMA==&mid=2247485510&idx=2&sn=0adff5754a2 ...

  9. 如何定位 Node.js 的内存泄漏

    基础知识 Node.js 进程的内存管理,都是有 V8 自动处理的,包括内存分配和释放.那么 V8 什么时候会将内存释放呢? 在 V8 内部,会为程序中的所有变量构建一个图,来表示变量间的关联关系,当 ...

  10. SQLServer中取当前年,月,日,时,分,秒

    Select GETDATE() as '当前日期',DateName(year,GetDate()) as '年',DateName(month,GetDate()) as '月',DateName ...