使用Javascript 實現 分享到 新浪微博 QQ 空間等

分類: JS 2012-09-10 15:34  8196人閱讀  評論(1)  收藏  舉報

咱們閱讀博客的時候常常會用到這樣功能,固然有時候也會想把本身的網站上也加入相似的分享功能,各大廠商已經給出了相應的API,點擊一個按鈕便可彈出窗口進入分享,咱們事先能夠設置一些參數,通常經常使用的就是 網站的網址,圖片還有一些內容描述。這裏我寫了三個方法,分別分享到 新浪微博,Q空間,以及騰訊微博 javascript


[javascript]  view plain copy
  1. <span style="font-size:24px;">var ShareTip = function()  
  2. {  
  3.     
  4. }  
  5. //分享到騰訊微博  
  6. ShareTip.prototype.sharetoqq=function(content,url,picurl)  
  7. {  
  8.  var shareqqstring='http://v.t.qq.com/share/share.php?title='+content+'&url='+url+'&pic='+picurl;  
  9.  window.open(shareqqstring,'newwindow','height=100,width=100,top=100,left=100');  
  10. }  
  11. //分享到新浪微博  
  12. ShareTip.prototype.sharetosina=function(title,url,picurl)  
  13. {  
  14.  var sharesinastring='http://v.t.sina.com.cn/share/share.php?title='+title+'&url='+url+'&content=utf-8&sourceUrl='+url+'&pic='+picurl;  
  15.  window.open(sharesinastring,'newwindow','height=400,width=400,top=100,left=100');  
  16. }  
  17. //分享到QQ空間  
  18. ShareTip.prototype.sharetoqqzone=function(title,url,picurl)  
  19. {  
  20.  var shareqqzonestring='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?summary='+title+'&url='+url+'&pics='+picurl;  
  21.  window.open(shareqqzonestring,'newwindow','height=400,width=400,top=100,left=100');  
  22. }  
  23. </span>  


 

 以上的函數分別具備三個參數,內容,網址,以及 圖片,也就是咱們想要分享的內容 php

 

測試代碼以下(咱們能夠寫在一個按鈕的單擊事件裏,關於按鈕的長相,這個本身定義 css

 

[javascript]  view plain copy
  1. <span style="font-size:18px;">var share1=new ShareTip();  
  2.   share1.sharetoqqzone("這是一本關於地圖故事的集錦,以一本書的形式來展現地圖故事,咱們能夠使用鼠標拖動來翻頁,或者點擊翻頁按鈕,點擊 立刻體驗,能夠體驗故事,同時在觸屏上也有很好的體驗效果奧,地圖故事,盡在書中,趕快體驗吧,建議使用對 HTML5支持較好的瀏覽器","http://tm.arcgisonline.cn:8038/App101/MapstoryBook/Default.html","http://tm.arcgisonline.cn:8038/App101/MapstoryBook/css/Img/ShareBook.jpg");</span>  
相關文章
相關標籤/搜索