1、首先要在頁面寫出點擊可進行微博分享的入口,樣式因自己項目而定:
<li class="bottomIcon_5 shareSina"><a href="javascript:;" target="_blank"></a><div class="shareTxt">微博</div></li>
2、其次,對微博按鈕進行點擊事件,也就是最重要的進行微博分享的操作:
// 微博分享 $('.shareSina').on('click', function () { window.sharetitle = $(".print-tit").html();//分享的標題 window.shareUrl = $(".myShare img").attr('src');//分享顯示的圖片 share(); }) function share() { (function(s, d, e) { try {} catch (e) {} var f = 'http://v.t.sina.com.cn/share/share.php?', u = window.location.href, p = ['url=', e(u), '&title=分享的名稱', '&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); }
點擊后會出現一個新彈窗的頁面,頁面內含有你要分享的圖片及網站的名稱、詳情等,頁面會跳轉到新浪微博,如果你已經登錄微博,那么會直接分享成功,如果沒有登陸,會跳轉到登錄頁面,登陸后直接分享成功。
3、這樣微博就分享成功了!