1.新浪微博的分享接口
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>
<p>点击下面的按钮可以将这段文字和图片分享到新浪微博哦!@邓波home</p>
<img src='https://app.yinxiang.com/shard/s53/res/283c5d6f-1599-4eeb-8392-6030f5c129a0' title='分享图片'/>
<input type="button" class="btn" id="btn" value='share'>
</div>
</body>
<script src='http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js'></script>
<script>
$('#btn').click(function(){
window.sharetitle = $(this).siblings('p').html();
window.shareUrl = $(this).siblings('img').attr('src');
share();
});
function share(){
//d指的是window
(function(s,d,e){try{}catch(e){}var f='http://v.t.sina.com.cn/share/share.php?',u=d.location.href,p=['url=',e(u),'&title=',e(window.sharetitle),'&appkey=2924220432','&pic=',e(window.shareUrl)].join('');function a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=620,height=450,left=',(s.width-620)/2,',top=',(s.height-450)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})(screen,document,encodeURIComponent);
}
</script>
</html>
在线预览:http://codepen.io/dddddd1/pen/ZBbZza
考虑到复杂多样的api
2.我们可以去使用jiathis去实现分享
http://www.jiathis.com/help/html/share-with-jiathis-api
http://www.jiathis.com/help/html/support-media-website
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>调用jiathis分享接口</title>
</head>
<body>
<div>
<p>点击下面的按钮可以将这段文字和图片分享到新浪微博哦!@邓波home</p>
<img src='https://app.yinxiang.com/shard/s53/res/283c5d6f-1599-4eeb-8392-6030f5c129a0' title='分享图片'/>
<input type="button" class="btn" id="btn" value='share'>
</div>
</body>
<script src='http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js'></script>
<script>
var url=window.location.href;
var title=document.title;
$('#btn').click(function(){
// window.open("http://www.jiathis.com/send/?webid=tsina&url="+url+"&title="+title); //新浪微博
// window.open("http://www.jiathis.com/send/?webid=qzone&url="+url+"&title="+title); //qq空间
});
</script>
</html>
在线预览地址:http://codepen.io/dddddd1/pen/eBpaQN