咱們閱讀博客的時候常常會用到這樣功能,固然有時候也會想把本身的網站上也加入相似的分享功能,各大廠商已經給出了相應的API,點擊一個按鈕便可彈出窗口進入分享,咱們事先能夠設置一些參數,通常經常使用的就是 網站的網址,圖片還有一些內容描述。這裏我寫了三個方法,分別分享到 新浪微博,Q空間,以及騰訊微博 javascript
- <span style="font-size:24px;">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');
- }
- </span>
以上的函數分別具備三個參數,內容,網址,以及 圖片,也就是咱們想要分享的內容 php
測試代碼以下(咱們能夠寫在一個按鈕的單擊事件裏,關於按鈕的長相,這個本身定義 css
- <span style="font-size:18px;">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");</span>