首页 > micolog, 博客相关 > 为博客添加分享按钮

为博客添加分享按钮

2010年9月24日 发表评论 阅读评论

有时,我们想为独立博客添加一个类似于分享到的按钮,以便分享到各种SNS网站添加人气。虽然,现在网上提供这种插件的网站,如addthisonjiathis等,但是,这些网站都是商业网站,为了流量,分享时会跳到上述网站,比较不爽。因此,求人不如求己,自己动手,丰衣足食,于是我搜了一下,看网上有没类似的代码,于是得到下述地址:

http://blog.csdn.net/skymountain/archive/2010/06/25/5694697.aspx

但是,我试用上述代码,发现在我micolog系统里没效,几番更改代码,终于出现了分享按钮图标,但是除图标外,还有一堆文字,看着不美观。于是,我再对代码进行修理,最终得到如下代码,其效果见本文标题下面:

 function ShareCode(server_url, server_icon_url,text){
    var title = encodeURIComponent(document.title.substring(0,76));
    var url = encodeURIComponent(location.href);
    server_url = server_url.replace("{title}",title);
    server_url = server_url.replace("{url}",url);

    return "<a href=\"javascript:window.open(\'"
    + server_url
    +"'); void 0\" title =\"" + text + "\"><IMG alt="
    + text + " src=\""
    + server_icon_url
    + "\"><\/a>"
}
function WriteSNS()
{
    document.writeln(ShareCode("http://share.renren.com/share/buttonshare.do?title={title}&link={url}",
    "http://s.xnimg.cn/favicon-rr.ico?ver=2",
    "Share to Renren"));

    document.writeln(ShareCode("http://www.kaixin001.com/repaste/share.php?rtitle={title}&rurl={url}",
    "http://www.kaixin001.com/favicon.ico",
    "Share to Kaixin"));

    document.writeln(ShareCode("http://v.t.sina.com.cn/share/share.php?title={title}&url={url}",
    "http://t.sina.com.cn/favicon.ico",
    "Share to SinaMicroblog"));

    document.writeln(ShareCode("http://www.douban.com/recommend/?url={url}&title={title}",
    "http://t.douban.com/favicon.ico",
    "Recomend to Douban"));

    document.writeln(ShareCode("http://apps.hi.baidu.com/share/?title={title}&url={url}",
    "http://www.baidu.com/favicon.ico",
    "Forword to BaiduHi"));


}
 

相比于原作者的代码,我做了以下改动:第一,设置分享打开页面为浏览器默认设置,而不会跳转到新的窗口;第二,对打开参数进行精简;第三,删除了按钮旁的文字进行,更加美观;第四,函数不是封装成div,这样可以更方便的贴到某一行内。

使用方法也很简单,在页面的任何一处假如js引用代码:

 <script type="text/javascript" src="/share.js"></script> 

在需要插入分享按钮的地方加入js函数调用代码即可:

 <script type="text/javascript">WriteSNS();</script>


本文作者: Sigma    在新浪微博关注SigmaSigmaWeibo    RSS订阅本博客
本文链接: http://www.sigma.me/2010/09/24/add_share_button.html
本博客采用知识共享署名—非商业性-禁止演绎使用3.0协议进行许可,转载请保留作者和原文链接。

  1. 2011年5月3日00:13 | #1

    这个语法高亮是syntax highlighter?跟syntax highlighter evolved有啥区别么?

  2. 2011年5月3日04:05 | #2

    @ouyang

    我也不知道,我一直想加上verilog支持,但一直没加上

  3. 2019年1月10日03:44 | #3

    I am writing to make you understand of the fine discovery my cousin’s daughter went through studying your web site. She learned several issues, with the inclusion of what it is like to have a marvelous giving style to have other folks with no trouble know several impossible matters. You really surpassed our desires. Many thanks for giving those warm and helpful, trustworthy, revealing and unique guidance on this topic to Julie.

  4. 2019年1月10日21:08 | #4

    My husband and i have been absolutely joyous Raymond managed to deal with his researching through your ideas he made using your site. It’s not at all simplistic just to continually be giving for free points people have been trying to sell. We really know we now have the blog owner to thank for that. These explanations you made, the simple website navigation, the relationships you make it possible to engender – it is mostly terrific, and it’s leading our son and our family feel that the issue is satisfying, and that is quite pressing. Many thanks for the whole thing!

  5. 2019年1月11日15:56 | #5

    I precisely desired to thank you so much once more. I am not sure what I would have used in the absence of the entire smart ideas revealed by you concerning such a industry. It absolutely was an absolute difficult condition in my circumstances, but considering this specialized fashion you solved that forced me to leap for contentment. Now i’m thankful for your support and hope that you find out what a powerful job you have been undertaking educating people by way of your webblog. Most probably you’ve never encountered all of us.

  6. 2019年1月12日09:49 | #6

    Thank you a lot for providing individuals with such a marvellous chance to check tips from this site. It is often very brilliant and as well , stuffed with amusement for me and my office acquaintances to visit the blog at the very least 3 times weekly to read the newest guides you will have. And lastly, I am also actually fascinated with your exceptional tips you give. Selected two areas in this posting are unequivocally the most suitable we’ve ever had.

  7. 2019年1月13日03:56 | #7

    I and my friends have already been looking at the excellent tips and hints found on your web blog while at once developed an awful suspicion I never expressed respect to the web blog owner for those techniques. All the young boys are actually as a consequence very interested to see them and have in effect in actuality been taking advantage of them. Thank you for truly being quite helpful and also for opting for varieties of really good useful guides most people are really desirous to learn about. Our sincere apologies for not saying thanks to you earlier.

  8. 2019年1月13日06:20 | #8

    I want to express my appreciation to the writer just for bailing me out of this type of condition. Because of looking through the the net and meeting solutions which were not beneficial, I was thinking my entire life was gone. Living without the presence of strategies to the difficulties you have solved by means of your entire blog post is a critical case, as well as the kind which could have in a wrong way damaged my entire career if I hadn’t discovered your website. Your own personal knowledge and kindness in maneuvering the whole thing was very useful. I am not sure what I would have done if I had not come upon such a solution like this. It’s possible to at this point look forward to my future. Thanks a lot so much for your impressive and sensible guide. I won’t think twice to recommend your blog to anybody who requires care on this subject matter.

  9. 2019年2月13日23:23 | #9

    lol. So let me reword this. Thank YOU for the meal!!

  10. 2019年2月14日03:46 | #10

    Thanks for the blog.Really looking forward to read more. Cool.

  11. 2019年2月18日22:21 | #11

    one is sharing information, that as truly good, keep up writing.

  12. 2019年2月22日17:50 | #12

    light bulbs are good for lighting the home but stay away from incandescent lamps simply because they produce so substantially heat

  13. 2019年2月23日11:37 | #13

    [url=http://buyjeacialonline.com/#]buy cialis online without prescription[/url] cialis generic where to buy cialis online forum

  14. 2019年2月23日19:29 | #14

    Thanks for sharing your thoughts. I really appreciate your efforts and I am waiting for your further write ups thank you once again.

  15. 2019年2月28日01:09 | #15

    [url=http://drcialonlinedkb.com/#]phentermine canadian pharmacy online[/url] cialis canada buy cheap viagra online canadian pharmacy

  16. 2019年2月28日22:37 | #16

    http://hitcialisosn.com/ canadian pharmacy online

  17. 2019年3月2日15:20 | #17

    http://mo-basta.org/ my canadian pharmacy

  18. 2019年3月6日03:43 | #18

    It’s really a nice and helpful piece of information.
    I am happy that you shared this helpful info with us. Please stay us up to date like this.
    Thanks for sharing.

  19. 2019年3月6日17:42 | #19

    hello there and thank you for your information – I’ve definitely picked
    up something new from right here. I did however expertise several technical issues using this web
    site, as I experienced to reload the web site lots of
    times previous to I could get it to load properly.

    I had been wondering if your hosting is OK? Not that I’m
    complaining, but slow loading instances times will very frequently affect
    your placement in google and can damage your high quality
    score if advertising and marketing with Adwords. Well I am adding this RSS to my email
    and could look out for a lot more of your respective interesting content.

    Make sure you update this again very soon.

  20. 2019年3月6日21:04 | #20

    Hi! I’ve been reading your blog for some
    time now and finally got the bravery to go ahead and
    give you a shout out from New Caney Texas! Just wanted to mention keep up the good
    work!

  21. 2019年3月7日00:16 | #21

    If some one desires to be updated with most recent technologies therefore he must
    be pay a quick visit this site and be up to
    date every day.

  22. 2019年3月7日00:51 | #22

    Keep up the superb piece of work, I read few posts on this web site and I believe that your blog is real interesting and contains sets of good info.

  23. 2019年3月8日00:11 | #23

    It’s difficult to find experienced people for this topic, however, you
    seem like you know what you’re talking about! Thanks

  24. 2019年3月9日22:58 | #24

    Definitely believe that which you said. Your favourite justification seemed to be on the net the
    simplest factor to remember of. I say to you, I definitely get annoyed whilst
    other people consider issues that they just don’t
    know about. You managed to hit the nail upon the top
    and outlined out the whole thing with no need side-effects , folks can take a signal.
    Will likely be again to get more. Thanks https://www.silicon-wristband.com

  25. 2019年3月10日22:54 | #25

    It’s really very complicated in this busy life to listen news on Television, so I simply use the web for that purpose, and take the most up-to-date information.

  26. 2019年3月11日02:16 | #26

    I know this if off topic but I’m looking into starting my own blog and was curious what all is needed to get setup?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet smart so I’m not 100% certain.
    Any tips or advice would be greatly appreciated. Thank you http://calltheweatherman.com/lva.php

  27. 2019年3月11日07:06 | #27

    Would you be fascinated by exchanging hyperlinks?

  28. 2019年3月12日06:24 | #28

    It’s genuinely very complicated in this busy life
    to listen news on TV, so I just use web for that purpose, and take the newest
    news.

  29. 2019年3月12日09:09 | #29

    Hi friends, how is the whole thing, and what
    you desire to say about this piece of writing, in my view its in fact remarkable in support of me.

  30. 2019年3月12日12:48 | #30

    If some one needs to be updated with hottest technologies after that
    he must be pay a visit this web page and be
    up to date all the time.

  31. 2019年3月13日00:48 | #31

    I am truly thankful to the owner of this web page who has shared this
    wonderful piece of writing at here.

  32. 2019年3月13日05:15 | #32

    I’m gone to convey my little brother, that he should also
    pay a quick visit this webpage on regular basis to take updated from latest gossip.

  33. 2019年3月13日08:39 | #33

    Thank you a bunch for sharing this with all people you really know what you are talking
    about! Bookmarked. Kindly additionally consult with my web site =).
    We may have a link trade contract among us

  34. 2019年3月13日09:16 | #34

    This paragraph is truly a good one it helps new net users, who are wishing in favor of
    blogging.

  35. 2019年3月13日09:52 | #35

    Great delivery. Outstanding arguments. Keep up the great effort.

  36. 2019年3月13日13:02 | #36

    Hi there, just became aware of your blog through Google, and found that it’s really informative.

    I am going to watch out for brussels. I’ll be grateful if you continue this in future.
    Lots of people will be benefited from your writing.

    Cheers!

  37. 2019年3月13日14:47 | #37

    Hey there! I’ve been reading your website for some time now
    and finally got the bravery to go ahead and give you a shout
    out from Porter Texas! Just wanted to mention keep up the
    good job!

  38. 2019年3月13日17:37 | #38

    I’m no longer positive where you are getting your information, however great topic.
    I must spend a while finding out much more or understanding more.
    Thanks for excellent information I used to be on the lookout for this info for my mission.

  39. 2019年3月14日15:28 | #39

    My partner and I stumbled over here from a different page and thought
    I might check things out. I like what I see so now i’m following you.
    Look forward to finding out about your web page again.

  40. 2019年3月15日01:48 | #40

    I quite like reading through a post that will make people think.
    Also, thank you for allowing for me to comment!

  41. 2019年3月15日02:33 | #41

    My brother recommended I might like this web site. He was entirely right.
    This post truly made my day. You cann’t imagine just how much time I had spent for
    this info! Thanks! https://www.trolleycoin123.com/blog/wp-login.php

  42. 2019年3月15日13:22 | #42

    Exceptional post but I was wanting to know if you could write
    a litte more on this topic? I’d be very thankful if
    you could elaborate a little bit further. Cheers!

  43. 2019年3月15日17:17 | #43

    I am sure this paragraph has touched all the internet users, its really really good post on building up new weblog.

  44. 2019年3月15日23:18 | #44

    I am actually happy to read this weblog posts which contains lots
    of valuable information, thanks for providing these
    statistics.

  45. 2019年3月16日16:39 | #45

    Hello! This is my first visit to your blog!
    We are a group of volunteers and starting a new initiative in a community in the same niche.
    Your blog provided us valuable information to work on. You have done a wonderful job!

  46. 2019年3月17日05:35 | #46

    Welcome to Morris Heating & Cooling Inc.

  47. 2019年3月17日12:20 | #47

    Howdy! Someone in my Facebook group shared this website with
    us so I came to take a look. I’m definitely enjoying the information. I’m book-marking and will be
    tweeting this to my followers! Excellent blog and terrific design and style.

  48. 2019年3月17日23:16 | #48

    Hello! I’m at work browsing your blog from my new iphone 4!
    Just wanted to say I love reading through your blog and look forward to all your posts!

    Carry on the outstanding work!

  49. 2019年3月18日19:25 | #49

    Thankfulness to my father who informed me concerning this web site, this
    web site is genuinely amazing.

  50. 2019年3月18日22:29 | #50

    I see something truly special in this website.

  51. 2019年3月19日20:14 | #51

    [url=http://niqabsquad.com/#]best place to buy cialis[/url] womens viagra canadian drug stores

  52. 2019年3月20日10:25 | #52

    Hey there! Would you mind if I share your blog with my twitter group?

    There’s a lot of people that I think would really appreciate your content.
    Please let me know. Many thanks

  53. 2019年3月20日14:06 | #53

    I was suggested this web site by my cousin. I’m not sure
    whether this post is written by him as nobody else know such detailed about my
    problem. You’re incredible! Thanks!

  54. 2019年3月21日05:50 | #54

    It’s hard to come by experienced people about this topic, however, you seem like you know what you’re talking about!
    Thanks

  55. 2019年3月21日15:06 | #55

    Do you have a spam problem on this site; I also am a blogger, and I was wanting to know your situation;
    we have developed some nice methods and we are looking to trade strategies with
    other folks, why not shoot me an e-mail if interested.

  56. 2019年3月21日17:18 | #56

    Excellent blog! Do you have any tips for aspiring writers?

    I’m hoping to start my own site soon but I’m a little
    lost on everything. Would you suggest starting with a free platform like WordPress or go for
    a paid option? There are so many options out there that I’m completely overwhelmed ..
    Any recommendations? Thanks a lot!

  57. 2019年3月22日03:16 | #57

    Hi there exceptional blog! Does running a blog similar to this take a massive
    amount work? I have very little knowledge of coding but I had been hoping to start my own blog in the near future.
    Anyways, should you have any suggestions or techniques for new blog owners
    please share. I understand this is off subject however I simply needed
    to ask. Cheers!

  58. 2019年3月22日05:14 | #58

    Undeniably consider that that you stated. Your favorite justification appeared to be at the internet the easiest factor to bear in mind of.

    I say to you, I certainly get irked even as other
    folks consider worries that they plainly do not understand about.
    You managed to hit the nail upon the top and also defined
    out the whole thing without having side effect , other folks can take a signal.

    Will likely be again to get more. Thanks

  59. 2019年3月22日05:46 | #59

    I am really impressed with your writing skills and also with the layout on your blog.
    Is this a paid theme or did you modify it yourself?
    Either way keep up the excellent quality writing, it
    is rare to see a nice blog like this one these days.

  60. 2019年3月22日06:01 | #60

    Hey would you mind sharing which blog platform you’re working with?
    I’m looking to start my own blog soon but I’m having a difficult
    time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most blogs
    and I’m looking for something completely unique.
    P.S Sorry for being off-topic but I had to ask!

  61. 2019年3月22日08:42 | #61

    I am regular visitor, how are you everybody?
    This piece of writing posted at this web site is truly pleasant.

  62. 2019年3月22日08:45 | #62

    Thanks in your curiosity in Investment Recommendation.

  63. 2019年3月23日01:40 | #63

    Hi I am so happy I found your webpage, I really found you by mistake, while
    I was searching on Aol for something else, Anyways I am here now and
    would just like to say cheers for a remarkable post and a
    all round entertaining blog (I also love the theme/design), I don’t have time to read it all at
    the moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be
    back to read more, Please do keep up the fantastic work.

  64. 2019年3月23日08:07 | #64

    First of all I want to say wonderful blog! I had a quick question which I’d like to ask if you
    do not mind. I was curious to find out how you center yourself
    and clear your thoughts prior to writing. I’ve
    had a difficult time clearing my mind in getting my ideas out there.
    I truly do enjoy writing however it just seems like the first 10 to 15 minutes are usually lost simply just trying to
    figure out how to begin. Any recommendations or hints?

    Appreciate it!

  65. 2019年3月23日09:12 | #65

    This design is wicked! You most certainly know how to keep
    a reader entertained. Between your wit and your videos,
    I was almost moved to start my own blog (well, almost…HaHa!) Great job.
    I really enjoyed what you had to say, and more than that,
    how you presented it. Too cool!

  1. 本文目前尚无任何 trackbacks 和 pingbacks.

无觅相关文章插件,快速提升流量