我们阅读博客的时候经常会用到这样功能,当然有时候也会想把自己的网站上也加入类似的分享功能,各大厂商已经给出了相应的API,点击一个按钮即可弹出窗口进入分享,我们事先可以设置一些参数,一般常用的就是 网站的网址,图片还有一些内容描述。这里我写了三个方法,分别分享到 新浪微博,Q空间,以及腾讯微博
[javascript]view plaincopy print? <spanstyle="font-size:24px;">varShareTip=function(){}//分享到腾讯微博ShareTip.prototype.sharetoqq=function(content,url,picurl){varshareqqstring='http://v./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){varsharesinastring='http://v./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){varshareqqzonestring='http://sns./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>
var ShareTip = function(){}//分享到腾讯微博ShareTip.prototype.sharetoqq=function(content,url,picurl){var shareqqstring='http://v./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./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./cgi-bin/qzshare/cgi_qzshare_onekey?summary='+title+'&url='+url+'&pics='+picurl;window.open(shareqqzonestring,'newwindow','height=400,width=400,top=100,left=100');}
以上的函数分别具有三个参数,内容,网址,以及 图片,也就是我们想要分享的内容
测试代码如下(我们可以写在一个按钮的单击事件里,关于按钮的长相,这个自己定义
[javascript]view plaincopy print? <spanstyle="font-size:18px;">varshare1=newShareTip();share1.sharetoqqzone("这是一本关于地图故事的集锦,以一本书的形式来展示地图故事,我们可以使用鼠标拖动来翻页,或者点击翻页按钮,点击马上体验,可以体验故事,同时在触屏上也有很好的体验效果奥,地图故事,尽在书中,赶快体验吧,建议使用对HTML5支持较好的浏览器",":8038/App101/MapstoryBook/Default.html",":8038/App101/MapstoryBook/css/Img/ShareBook.jpg");</span>
var share1=new ShareTip();share1.sharetoqqzone("这是一本关于地图故事的集锦,以一本书的形式来展示地图故事,我们可以使用鼠标拖动来翻页,或者点击翻页按钮,点击 马上体验,可以体验故事,同时在触屏上也有很好的体验效果奥,地图故事,尽在书中,赶快体验吧,建议使用对 HTML5支持较好的浏览器",":8038/App101/MapstoryBook/Default.html",":8038/App101/MapstoryBook/css/Img/ShareBook.jpg");